Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the JavaScript comma operator

Shulou Source: shulou.com Published: 2022-06-01 04:24:40 09月29日 Update

Editor to share with you how to use the JavaScript comma operator, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Comma operator

I was surprised when I realized that the comma (,) was a separate operator and I had never noticed it before. I've used a lot of commas in my code, but I've never realized its other uses.

Operator is used to calculate each of its operands from left to right and returns the value of the last Operand.

Let count = 1 ret = (count++, count); console.log (ret); copy code

In the above example, the value of the variable ret will be 2. Similarly, the following code records the output value of 32 in the console to the console.

Let val = (12,32); console.log (val)

Where do we use it? Any ideas? The most common use of the comma (,) operator is to provide multiple parameters in a for loop.

For (var I = 0, j = 50; I

Tags: Operators commas operations code articles never content consciousness console Operand face control not much then parameters variables multiple most common ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia Microsoft Shulou Technology Xiaomi