js in the "==" implicit conversion rules

1. When comparing the object and Boolean object converted to a string, then converted to digital, a digital direct conversion Boolean

[] == false

The result is to true, [] is converted to a string '', then converted to a digital 0, is converted to a digital 0 to false

2. Objects and strings are compared, the object is converted to a string, and then compares the two

[1,2,3] == '1,2,3'

The result is to true [1,2,3] into ', 2,3'

3. Object and a digital comparator, the object into a string, and then converted to digital, and then compares the digital

[1] == 1

The result is true, [1] is converted to '1' and then converted to a

And a digital comparator 4. string, the string is converted to a digital

'1' == 1

5. strings and Boolean values ​​are compared, both then compare values ​​all converted into

'1' == true

6. Boolean and as a number, is converted to a digital Boolean

true == 1

Conversion diagram

 

Compare special

== undefined null  // true comparison returns true null and undefined, and both the other comparison values returned to false 
Number The ( null ) // 0

 

Guess you like

Origin www.cnblogs.com/wangxirui/p/11655865.html
Recommended