JavaScript Operator Precedence

前端 未结 2 889
一向
一向 2021-01-29 07:30

According to Mozilla, the === operator has higher precedence than the || operator, which is what I would expect.

However this statement evaluates to the number 1, rathe

2条回答
  •  臣服心动
    2021-01-29 08:35

    Higher operator precedence is like a parenthesis around the operands.

    let x = 1 || (0 === 0);
    

    The second part gets never evaluated, because of the truthy value of 1 .

提交回复
热议问题