[removed] the confuse about comparison “2 == true”

前端 未结 2 1185
我在风中等你
我在风中等你 2021-01-20 10:11

Here is a javascript comparison:

2 == true //false

it\'s said, the reason why return false, is because the comparison convert the tru

2条回答
  •  再見小時候
    2021-01-20 10:45

    I find the doc here:

    Comparison Operators, which said:

    If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the other operand is converted to a string if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

提交回复
热议问题