What does a comma do in JavaScript expressions?
Solution 1:
The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.
Source: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Special_Operators/Comma_Operator
For example, the expression 1,2,3,4,5
evaluates to 5
. Obviously the comma operator is useful only for operations with side-effects.
console.log(1,2,3,4,5);
console.log((1,2,3,4,5));
Solution 2:
Some more to consider:
console.log((0, 9));
console.log((9, 0));
console.log(("foo", "bar"));
Solution 3:
The comma operator evaluates both of its operands (from left to right) and returns the value of thesecond
operand.
https://stackoverflow.com/a/3561056/5934465
It should be like this!
The comma operator evaluates each of its operands (from left to right) and returns the value of the
last
operand.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator