There are 5 types of data in javascript: Undefined, Boolean, Object, number, String, and these types of data, when they are in an expression, The JS parser automatically converts it to a Boolean value to determine which logical branch the current condition conforms to (of course, we can also manually convert by invoking the Boolean (Var) method, which determines the code that executes the method body, which converts the values of these types to Boolean What are the rules to follow?
data type |
convert to True value |
convert to False value |
undefined |
|
undefined |
boolean |
true |
false |
non-null is true |
null |
number |
|
0 and Nan |
Non-empty string |
"" (empty string) |
The above is the conversion rules JS, in the development, we must carefully analyze the possible value of variables and conversion values, if expected to get true but get false, the world will flip over slightly ^_^
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/