In a nutshell: ==Convert the type first and then compare it, ===Judge the type first, if it is not the same type, it is directly false.
=== means that the two sides of the comparison must be absolutely the same
alert(0 == ""); // true alert(0 == false); // true alert("" == false); // true
alert(0 === ""); // false alert(0 === false); // false alert("" === false); // false
Let’s talk about ===, this is relatively simple, the specific comparison rules are as follows:
1. If the types are different, they are [unequal]
2. If both are numerical values and are the same value, then [equal]; (!Exception) is, if at least one of them is NaN, then [not equal]. (To determine whether a value is NaN, you can only use isNaN() to judge)
3. If both are strings and the characters in each position are the same, then [equality]; otherwise [not equal].
4. If both values are true, or both are false, then [equal].
5. If both values refer to the same object or function, then [equality]; otherwise [not equal].
6. If both values are null, or both undefined, then [equal].
Besides, the specific comparison rules are as follows:
1. If the two value types are the same, perform === comparison, and the comparison rules are the same as above.
2. If the two value types are different, they may be equal. Type conversion is performed according to the following rules and then compare:
a. If one is null and the other is undefined, then [equal].
b. If one is a string and the other is a numeric value, convert the string into a numeric value and then compare it.
c. If any value is true, convert it to 1 and compare it; if any value is false, convert it to 0 and compare it.
d. If one is an object and the other is a numerical or string, convert the object into a value of the base type and then compare it. Convert an object to a basic type and use its toString or valueOf method. The js core built-in class will try to precede toString; the exception is Date, which uses toString conversion. Non-JS core object, let's say (it's more troublesome, I don't understand much)
e. Any other combination (array array, etc.), are [unequal].