0

I've seen in JavaScript code like:

var x = (1, 2);

which would then evaluate x to 2. Also

var x = (false, 2);

also evaluates x to 2, or any other value (so it doesn't appear to be identical to var x = false || 2).

It would appear so far that the value of x in this case is always equal to the second comma-separated value, so then what's the point exactly? What does the expression var x = (y, z); do?

bluejayke
  • 2,773
  • 2
  • 20
  • 50
  • As for "What's the point?": https://stackoverflow.com/questions/9579546/when-is-the-comma-operator-useful – John Montgomery Mar 27 '20 at 19:51
  • And here's a more detailed description: https://stackoverflow.com/questions/27217112/unfamiliar-variable-assignment-with-parenthesis-and-commas – Dave Mar 27 '20 at 19:53

0 Answers0