What does a comma do in JavaScript expressions?

前端 未结 5 1545
礼貌的吻别
礼貌的吻别 2020-11-21 05:22

If I use:

1.09 * 1; // returns \"1.09\"

But if I use:

1,09 * 1; // returns \"9\"

I know that 1,09 isn\'t

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 06:04

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

    https://stackoverflow.com/a/3561056/5934465

    It should be like this!

    The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

提交回复
热议问题