Skip to content Skip to sidebar Skip to footer

Javascript Expression In Parentheses

var x = (1,2,3); alert(x); This expression evaluates to 3. How is this expression (1,2,3) called? Why does it return 3?

Solution 1:

Javascript has a commaoperator, like C does. It evaluates each of the expressions, then returns the last one.

Solution 2:

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.

Post a Comment for "Javascript Expression In Parentheses"