In javascript, you can use = to compare whether the two data types are equal. If the two data types are different, the data will be compared after conversion. The conversion rules are as follows:
L if the type of one of the operands is Boolean, first convert it to numeric type, false to 0, and true to 1.
L if one of the operands is a string and the other is a number, convert the string to a number for comparison.
L if one of the operands is of the string type and the other is of the object type, the string will be compared after the toString method of the object is called.
L if one of the operands is numeric and the other is object, convert the object to a numeric value and compare the numbers.
The following provides some special comparisons:
L null and undefined are equal.
L null and undefined are not converted to any other types.
L if the result of any operation is NaN, if the comparison is equal, false is returned. If the comparison is not equal, true is returned. Note: Even if both operands are NaN, the returned result is false, that is, NaN is not equal to NaN.
L if both operands are objects, compare the referenced values. If the same object is referenced, true is returned. Otherwise, false is returned.
Alert (null = undefined); // true
Alert (undefined = null); // true
Alert (true = 1); // true
Alert (false = 0); // true
Alert (true = 2); // false
Var obj = {};
Alert (10 = obj); // false
Identical comparison ===and not completely equal! =
The exact same comparison is used to compare whether non-conversion is equal. For example:
Var a = "100 ";
Var B = 100;
Alert (a = B); // true
Alert (a = B); // false
= The comparison returns true because "100" is first converted to the number 100, and then compared with the number 100, the result is equal.
=== The comparison returns false because the string "100" is not converted and is not equal to the number 100.
! = Used to compare whether the comparison is not equal without conversion.
Alert (! = B); // false
Alert (! = B); // true
In the first case, false is returned, because the converted values are equal. In the second case, the true result is returned, because if no conversion is performed, one of them is a string, the other is a number, and the other is not equal.