1

This was a question I was asked and was completely stumped.

var a = (1, 2, 3);
console.log(a);

I found out that a = 3 and was wondering why the value is equaled to the last number in the parenthesis. It works the same if there were strings. This confused me since I never seen the value of a variable cited in parenthesis, when would someone use this?

morizvi23
  • 233
  • 2
  • 4
  • 10
  • 3
    See this - http://stackoverflow.com/questions/27217112/unfamiliar-variable-assignment-with-parenthesis-and-commas – George Kagan Nov 04 '16 at 19:16
  • Or even this - http://stackoverflow.com/questions/440739/what-do-parentheses-surrounding-a-javascript-object-function-class-declaration-m – rafaelbiten Nov 04 '16 at 19:18
  • please welcome the [comma operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator)! – Nina Scholz Nov 04 '16 at 19:25
  • Why do you think the value has multiple data types? They're all numbers. – Barmar Nov 04 '16 at 19:37

0 Answers0