If one of the operands is of type Boolean, first convert it to a number type, false to 0, and true to 1.
If the type of one of the operands is a string and the other is a numeric type, then the string is converted to a number for comparison.
If the type of one of the operands is a string and the other is of type object, then the object's ToString method is called after the string is compared.
If the type of one of the operands is a numeric type and the other is of type object, then a numeric comparison is made after the objects are converted to numeric values.
Some special comparisons are made in the following provisions:
null and undefined are equal.
Null and undefined are not converted to any other type
If the result of any one operation is NaN, then the equality comparison returns false, and the inequality comparison returns true.
Note that even if the two operands are Nan, the returned result is false, that is, Nan is not equal to Nan.
If the two operands are objects, then the values they reference are compared, and if the same object is referenced, the return is true, otherwise, false is returned.
alert (null = = undefined); // alert (undefined = = null ); // alert ( true = = 1); // alert (false = = 0); // alert (true = = 2); // var obj = {}; alert ( = = obj); //
View Code
The exact same comparison = = = And not exactly equal!==
The exact same comparison is used to compare whether the conversion is not equal, for example:
var a = "$"var B = +/ /// false
View Code
The = = Comparison returns true because "100" is first converted to the number 100 and then compared with the number 100, resulting in equality.
= = = The comparison will return false, because the string "100" is not converted, and the number 100 is not equal.
!== are used to compare whether they are not equal in the case of non-conversions.
// true
View Code
The first case will return false, since the conversion is equal. The second case will return true, because without conversion, they are a string, a number, and not equal.
Equality and unequal operation in JS