The comma operator allows the execution of more than one operation in a single statement.

Following example shows how that works:

var val1 = 1, val2 = 8, val3 = "hehe", val4 = null

Most of the time the comma operator is used to assign values to variables.

There are other situations when this kind of operator becomes handy as well. The example below shows one of the situations:

for (var i = 0, j = 99; i <= 99; i++, j--) {


In the example above, two variables are set in the same statements and will be operated at the same time throughout the for loop statement (to learn more about loops, follow this link).


›› go to examples ››