I was surprised to see the result of this line of code:
const what = (1,2,3,4); console.log(what); //=> 4
I asked around on twitterarrow-up-right and learned that the syntax construct at play here is the comma operatorarrow-up-right.
The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.
And that is why what gets bound to 4.
what
4
Last updated 4 years ago