Boolean type
This type is only one word par value: true and false.
Various data types and their corresponding conversion rule:
Data type is converted to the true value is converted to the true value
Boolean true false
String any non-empty string "" (an empty string)
Number any nonzero numeric value (including infinity) and NaN 0 (see later in this chapter in relation NaN)
Object Any object null
Undefined n/a① undefined
Note that, undefined is converted to false, 0 is converted to false, so that, for numerical determination requires additional care if, for example:
function test( num ) {
if ( !num ) return;
...
}
test(); // !num 为true,return;
test (0);! // it is passed though the value 0, but num is true, return;
(! Num) if the object itself may be determined whether a transfer value is determined, but when the value 0 is passed, the value would be considered not passed;