= Equality, === identity.
=, When the value types on both sides are different, type conversion should be performed first and then comparison should be made.
=, No type conversion is required. The types may vary.
The descriptions are as follows:
=, Which is relatively simple. The following rules are used to determine whether two values are equal:
1. If the types are different, [not equal]
2. If both are numerical values and the values are the same, [equal]; (! If at least one of them is Nan, [not equal]. (You can only use isnan () to determine whether a value is Nan)
3. If both are strings and the characters at each position are the same, [equal]; otherwise [not equal].
4. If both values are true or false, [equal].
5. If both values reference the same object or function, [equal]; otherwise [not equal].
6. If both values are null or undefined, [equal].
Then, according to the following rules:
1. If the two values are of the same type, compare them with =.
2. If the two values have different types, they may be equal. Perform type conversion and comparison based on the following rules:
A. If one is null and the other is undefined, [equal].
B. if one is a string and the other is a numerical value, convert the string to a numerical value before comparison.
C. If any value is true, convert it to 1 for comparison. If any value is false, convert it to 0 for comparison.
D. If one is an object and the other is a value or string, convert the object to a base type value before comparison. Converts an object to a base type and uses its tostring or valueof method. JS core built-in class, will try valueof prior to tostring; the exception is date, date uses tostring conversion. Non-js core objects (not familiar to me)
E. Any other combinations are [not equal].
Example:
"1" = true
Type. True is converted to the value 1 first. Now it is converted to "1" = 1, and then "1" is converted to 1, which is equal to 1 = 1.
= Value assignment operator
= Equal
=== Strictly equal
Example:
VaR A = 3;
VaR B = "3 ";
A = B returns true
A = B returns false
Because A and B are of different types
=== Used for strict comparison and judgment