The JavaScript Comma Operator


Operator precedence is something that pretty much has me paranoid when programming. I know for a fact that over the years it’s resulted in way too many parenthesis “just to be sure” and has been the cause of a number of head scratching bugs during development. It’s no surprise that JavaScript throws me for another loop when it comes to it’s comma operator. As it’s defined:

The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.

This is kind of wild, and if I’m truthful I’ve never had a reason to use it. Or have I. Maybe since I simply didn’t realize it’s existence, the operator seems a bit useless on the surface. As per this article though, I could be severely mistaken.