The JavaScript Comma Operator

Posted: May 03, 2013 Comments

View http://javascriptweblog.wordpress.com/2011/04/04/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.

Get my newsletter

Receive periodic updates right in the mail!
  • This field is for validation purposes and should be left unchanged.

Leave a Reply

Your email address will not be published.