Comma operator returns first value instead of second in argument list?

前端 未结 3 994
余生分开走
余生分开走 2020-12-14 12:31

MDN claims that:

The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand

3条回答
  •  一向
    一向 (楼主)
    2020-12-14 12:53

    When you use it like that, the comma is not an operator, it's a separator between the parameters in the call to the alert method.

    If you put parentheses around them so that it's an expression, it will show you 2:

    alert( (1,2) );
    

提交回复
热议问题