The equality operator operates as follows:

1. If two values are of the same type, compare ===.

(ps: = = [], [] {} = = {} type is the same, compare the = = =, where the address is different, so return false)

2. If two values have different types, they may be equal.

Use the following rules to cast and compare:

(1) If null and undefined, then [equal].

(2) If either value is a string and the other value is a number, convert the string to a number before comparing equality; Call the Number() function.

(3) If any value is a Boolean, convert it to a value before comparing the equality, that is, call the Number() function.

(4) If one is an object and the other is a number or string, convert the object to a value of the underlying type and compare. The object is converted to the base type using its toString or valueOf methods. The js core built-in class will try valueOf before toString; But Date uses the toString conversion.

(ps: [] ==! []! Better than converting = = so [] = = false – > [] = = 0 – > ‘= = 0 so returns true)

(ps: {} ==! {} – > {} = = false – > {} = = 0 – > [object object] = = 0 so return false)

Supplement:

The return valueOf the valueOf() method for different types of objects
object The return value
Array Returns the array object itself.
Boolean Boolean value.
Date The stored time is millisecond UTC from midnight on January 1, 1970.
Function The function itself.
Number A numeric value.
Object The object itself. This is the default.
String String value.
Math and Error objects do not have valueOf methods.