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

后端 未结 6 1790
清酒与你
清酒与你 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:24

    true && 1 => this will always return the last value of && if all conditions are true or false otherwise

    true || 1 => this will always return the first 'truthy' value

    Resources:

    http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf

提交回复
热议问题