An equal sign is a value assignment. The main problem is the difference between two and three equal signs.
The difference between two equal signs and three equal signs in javaScript
In a word: = convert the type before comparison, = first judge the type, if not the same type, it is directly false.
===Indicates constant equals, and the two sides of the comparison must be absolutely the same
Alert (0 = ""); // true
Alert (0 = false); // true
Alert ("" = false); // true
Alert (0 = ""); // false
Alert (0 = false); // false
Alert ("" = false); // false
Let's start with =. This is relatively simple. The comparison rules are as follows:
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].
Besides, the comparison rules are as follows:
1. If the two values are of the same type, the comparison rules are as follows:
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 (I don't know much about it)
E. Any other combinations (array, etc.) are [not equal].
When a person cannot find a way out, the best way is to achieve the ultimate in what can be done now, so that no one can do it.