Determine whether two variables are equalProgramVery important computation in design. This operation is quite simple when processing the original value, but it is a little complicated to design the object. Javascript provides two sets of operators to handle this problem. equal signs and non-equal signs are used to process the original values. Full and non-full signs are used to process objects.
In JavaScript,The equal sign is represented by the double equal sign (= ).,Returns true if and only if the number of two operations is equal..The non-equal sign is an exclamation point plus an equal sign (! =), Returns true if and only if the number of two operations is not equal. To determine whether two arithmetic operations are equal, both operators perform type conversion.
The basic rules for executing type conversion are as follows:
If a number is a Boolean value, convert it to a numeric value before checking equality. Convert false to 0, and true to 1.
If one operation is a string and the other is a number, convert the string to a number before checking for equality.
If one operation is an object and the other is a string, you must convert the object to a string (call the tostring () method) before checking equality ).
If one operation is an object and the other is a number, convert the object to a number before checking for equality.
During comparison, this operator also complies with the following rules:
The null and undefined values are equal.
When equality is checked, null and undenfined cannot be converted into other values.
If the number of operations is Nan, the equal sign returns false, and the non-equal sign returns true. Important: even if the number of connected operations is Nan, the equal sign still returns false, because according to the rule, Nan is not equal to Nan.
If both operations are objects, their reference values are compared. If the number of two operations points to the same object, the equal sign returns true; otherwise, the number of two operations varies.
The comparison below lists some special cases and their results:
Null = undefined // The result is: True
"Nan" = Nan // The result is: false.
5 = Nan // The result is: false
Nan = Nan // The result is: false.
Nan! = Nan // The result is: True.
False = 0 // The result is: True.
True = 1 // The result is: True
True = 2 // The result is: false
Undefined = 0 // The result is: false
Null = 0 // The result is: false
"5" = 5 // The result is: True