the "= =" Symbol and the Boolean conversion rule in JS
What is the rules for how = = converts types?
Comparison rules for "= =":
1. Comparing numbers and strings would always convert the strings to numbers.
The number type is compared to the string type, and the string is converted to the number type. Example: 2== "2" true
2. Null and undefined would always equal the other.
The null type is always equal to the undefined type comparison. such as: var a = null,b; Then A==b is true.
3. Comparing Booleans to any other type would always cause the booleans to being converted to numbers.
A Boolean type is compared to any other type, and the Boolean type is converted to the number type. For example: var a = 0, B = false; A==b is true
4. Comparing numbers or strings to objects would always cause the numbers or strings to being converted to objects.
The number type or string type is compared to the object type, and number or string type is converted to type object. For example: var a = 0, b = {}; A==b is False
The rules for converting and types to Booleans is actually relatively straightforward:
about other types of rules that are converted to Boolean types:
1. Undefined and null is always false.
2. Booleans is just treated as booleans (obviously).
3. Numbers is false if they equal 0 or NaN; Otherwise, they ' re true.
4. Strings is true, except for the empty string "", which is false.
5. Objects is always true.
the "= =" Symbol and the Boolean conversion rule in JS