开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜