C comma operator

Section 6.6/3, “Constant expressions”, of the ISO C99 standard is the section you need. It states: Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated. In the C99 rationale document from ISO, there’s this little snippet: An integer constant expression … Read more

What does the comma operator do in JavaScript?

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));

What does a comma do in JavaScript expressions?

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));

When is the comma operator useful?

The following is probably not very useful as you don’t write it yourself, but a minifier can shrink code using the comma operator. For example: if(x){foo();return bar()}else{return 1} would become: return x?(foo(),bar()):1 The ? : operator can be used now, since the comma operator (to a certain extent) allows for two statements to be written … Read more