1. Equal == and unequal!=
Convert operands first and then compare equality
When converting different data types, equality and inequality follow the following rules:
1.1 If an operand is a Boolean, convert it to a numeric value before comparing the equality---false to 0 and true to 1;
1.2 If one operand is a string and the other is a numeric value, convert the string to a numeric value before comparing the equality.
1.3 If one operand is an object and the other is not, then the valueOf() method of the object is called and the obtained basic type value is compared according to the previous rules.
1.4 null and undefined are equal
1.5 null and undefined cannot be converted to any other value before comparing equality
1.6 If there is an operator that is NaN, the equal operator returns false, and the unequal operator returns true; even if both operands are NaN, the same is true.
1.7 If both operands are objects, compare whether they point to the same object
| expression | value |
| null == undefined | true |
| "NaN" == NaN | false |
| 5 == NaN | false |
| NaN == NaN | false |
| NaN != NaN | true |
| 5 =="5" | true |
| false == 0 | true |
| true == 1 | true |
| true == 2 | flash |
| undefined == 0 | false |
| null == 0 | false |
2. Congruent === and totally different!==
Two operands return true equally without conversion, and false if not equally;
undefined == null;//true
undefined === null;// false
The above detailed explanation of JS's equal operator is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.