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

Uses of C comma operator [duplicate]

C language (as well as C++) is historically a mix of two completely different programming styles, which one can refer to as “statement programming” and “expression programming”. As you know, every procedural programming language normally supports such fundamental constructs as sequencing and branching (see Structured Programming). These fundamental constructs are present in C/C++ languages in … Read more

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

How does the Comma Operator work

Take care to notice that the comma operator may be overloaded in C++. The actual behaviour may thus be very different from the one expected. As an example, Boost.Spirit uses the comma operator quite cleverly to implement list initializers for symbol tables. Thus, it makes the following syntax possible and meaningful: keywords = “and”, “or”, … Read more