Comparison conversion rules between different data types in js for implicit conversion are as follows:
1. Comparison between objects and boolean values
When an object is compared with a Boolean value, the object is first converted to a string and then to a number. The Boolean value is directly converted to a number.
[] = True; // false [] convert to string '', then convert to number 0, true to number 0, so false
2. Comparison between objects and strings
When the object is compared with a string, the object is converted to a string, and then the two are compared.
[, 3] = '1, '// true [, 3] is converted to '1, 2, 3', then and '1, 2, 3 ', so returns true;
3. Comparison of objects and numbers
When comparing an object with a number, the object is first converted to a string, then converted to a number, and then compared with a number.
[1] = 1; // true: the object is first converted to a string and then to a number, and then compared with [1] => '1' => 1, so the result is true.
4. Comparison of strings and numbers
When comparing a string and a number, convert the string to a number and then compare the two.
'1' == 1 // true
5. Comparison of string and boolean values
When the string and boolean values are compared, both are converted to numerical values and then compared.
'1' == true; // true
6. Comparison of Boolean values and numbers
When a Boolean value is compared with a number, the Boolean value is converted to a number and the two are compared.
true == 1 // true
Many children's shoes that just came into contact with js have seen so many conversion rules. In fact, the rule is very simple. You can write down this picture (it's time to show my superb painting skills)
In addition, let's look at some things that require "special care.
Let's look at an interesting question.
[] == false;![] == false;
The two results are true. The first one is: object => string => value 1 false to convert to Number 1. This is true. It should be OK,
The second front side has more !, Convert it to a Boolean value and return the inverse value. If it is converted to a Boolean value, all null strings (''), NaN, 0, null, and undefined return true! [] This [] => true returns false, so [] = false is true.
There are also some things to remember, such:
Undefined = null // true returns true when comparing undefined and null, and returns falseNumber (null) when comparing them with other values // 0