JavaScript type conversion: (true && 1) vs (true | | 1)

后端 未结 6 1808
清酒与你
清酒与你 2020-12-09 17:31

JavaScript is non-strictly typed language as Java,for example.

As we know, it converts value of result dependently upon context:

\"2\" + \"3\" r

6条回答
  •  渐次进展
    2020-12-09 18:21

    This has nothing to do with type conversion.

    || returns the first truthy operand. 1 || true will give you 1

    && returns the first falsy operand, or the second operand if both are truthy.

    See page 58 of the ECMAScript specification

提交回复
热议问题