Rules for data type conversions
- 1 if there is only one value, judging whether this value is true or FALSE, follow only 0,nan, ' null,undefined these five are false and the rest are true
- 2 If two value comparisons are equal, follow these rules:
-
![] ->false
-
[]==[]->false
- //val==val Two values may not be of the same data type, if two equals sign comparison, The default data type conversion
- rule:
- 1 Object = = object is never equal
- 2 Object = = String
- First convert the object to a string (method called ToString), Then compare
- [] empty array to string is '
- {} Convert to String "[Object,objec]"
The
- 3 Object = = Boolean type
- object first converts the string (tostring method), then converts the string to a digit (number, "" The empty string is 0), the Boolean type is converted to a number (true is 1,false is 0), and finally two numbers Word comparison
[]==false->true
- 4 Object = = Number
- First convert the string to a string (toString) and then convert the string to Number, and then compare
- 5 Number = = Boolean
- convert Boolean to number
- 6 Number = = String The
- string is converted to a number
- 7 String = = Boolean
- 8 null==undefined result is true;
- 9 null or undefined and any other data type comparisons are not equal
- 3 except = = is compared, = = = Comparison (absolute comparison)
- val = = = Val2 Compares data types if the data types are different and certainly not equal
===============================================================================================================================
Two values are compared, and if the data type is different, the default data type conversion
Object = = object: Compare the memory addresses of the respective representatives, the same address, and the different addresses are unequal
Object = = Number: First the object is ToString, then the result is the number, and the final comparison with the numbers
Object = = String: The object is first ToString and then compared
Object = = Boolean: All converted to digital
-String = = Number: string converted to Digital
-String = = Boolean: All converted to digital
Boolean = = Number: Boolean converted to Digital
->null = = undefined are equal, they are equal to themselves, besides and any other value do not want to wait
->nan = = NaN is not equal
Converts a value to a Boolean type: The!、!!、 boolean, if (num) condition means that you first convert num to Boolean to verify true or False
Only ', 0, NaN, null, undefined for false, the rest is true
! [] = = false: two = = The priority of the judgment is the lowest, it must be the right and left side of the expression, the results of the implementation of the comparison
! [] Convert to Boolean and then take back->false =>true
Conversion rules for JS data types