Did you know how to use comma operator in Javascript? A simple ,
can separate expressions in the same statement, evaluate left-to-right in the expression, pick the right most valid value as the result, and confuse other developers - all within the blink of an eye.
We have discussed about operators when discussing operator precedence. But the no. of uncommon operators are more than the typical bunch.
Oh, and btw, comma has the lowest precedence amongst all operators.
Let us look at a few examples involving comma operator.
|
|
An example in real world -
|
|
Just imagine comma happening to your production program, and shudder.
But, it’s not all that bad. Sometimes you would have used the humble comma without even realizing its presence.
|
|
Still think it is bad? Yep - I am totally with you.