The comma operator has left-to-right associativity. Two expressions separated by a comma are evaluated left to right.
In the example below, the comma , operator is used to evaluate multiple expressions and returns the value of the last operand.
var x = 10; var y = 10; var txt; //using comma operator var A = (x++, x); var B = (y+=5, y*=2, y); //displaying result txt = "(x++, x) : " + A + "<br>"; txt = txt + "(y+=5, y*=2, y) : " + B;
The output (value of txt) after running above script will be:
(x++, x) : 11 (y+=5, y*=2, y) : 30