Javascript conditional statement with a single pipe “|”

后端 未结 4 622
暖寄归人
暖寄归人 2020-12-12 01:32

Just wondering if anyone has come across this before.

I found in a project (that was handed over from another developer) a conditional statement that looked somethin

4条回答
  •  庸人自扰
    2020-12-12 02:11

    | is a bitwise OR, which in some very limited cases can substitute the ||.

    An important difference is that with | both operands are evaluated, unlike with the || which evaluates the second operand only if the first is false.

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

提交回复
热议问题