What's going on here using JavaScript?
var c = +(3,13);
I got c equals to 13. Why?
What's going on here using JavaScript?
var c = +(3,13);
I got c equals to 13. Why?
The comma functions as an expression separator operator. The value of a sequence of expressions separated by commas is the value of the last expression. Thus 3, 13
has the value 13
. That's surrounded with parentheses and the unary +
operator, neither of which will affect that value.
The comma operator is useful in only a small number of situations, generally involving expressions with side effects. In particular, your example is basically pointless. However, there are situations where some statement syntax allows for a single expression, so the comma operator lets you sneak in more than one.