1. Equal = = and unequal!=
Convert operands first and then compare equality
Equality and inequality follow the following rules when converting different data types:
1.1 If one operand is a Boolean, convert it to a numeric value---False to a 0,true conversion to 1 before comparing equality;
1.2 If one operand is a string and the other operand is a numeric value, convert the string to a numeric value before comparing equality
1.3 If an operand is an object, another is not, then the valueof () method of the object is invoked, and the resulting base type value is compared with the preceding rule
1.4 null and undefined are equal.
1.5 You cannot convert null and undefined to any other value until you compare equality
1.6 If an operator is Nan, the equality operator returns FALSE, and the inequality operator returns true, even if the two operands are Nan.
1.7 If two operands are objects, compare whether they point to the same object
An 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 |
Flase |
Undefined = 0 |
False |
NULL = 0 |
False |
2. Congruent = = and full inequality!==
Two operands equal returns True when not converted, and not equal returns false;
undefined = = Null;//true
Undefined = = null;//false
The above JS equality operator is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.