Javascript expression in parentheses
var x = (1,2,3);
alert(x);
This expression evaluates to 3.
How is this expression (1,2,3)
c开发者_StackOverflowalled? Why does it return 3?
Javascript has a comma operator, like C does. It evaluates each of the expressions, then returns the last one.
I haven't seen this in Javascript before. But in a number of other C'ish languages, it basically evaluates each of the expressions in the parentheses and returns the value of the last one.
精彩评论