It is usually necessary to determine the true or false in the following statement Structure
If branch statement
While loop statement
The second statement in
For example
Copy codeThe Code is as follows:
If (boo ){
// Do something
}
While (boo ){
// Do something
}
The six values in JavaScript are "false", and these six values are
False
Null
Undefined
0
''(Null String)
NaN
Here, false is a boolean type, but the other five are not.
In addition to these six, all others are "true", including objects, arrays, regular expressions, and functions. Note that '0', 'null', 'false', {}, and [] are also true values.
Although all these six values are "false", they are not all equal.
Copy codeThe Code is as follows:
Console. log (false = null) // false
Console. log (false = undefined) // false
Console. log (false = 0) // true
Console. log (false = '') // true
Console. log (false = NaN) // false
Console. log (null = undefined) // true
Console. log (null = 0) // false
Console. log (null = '') // false
Console. log (null = NaN) // false
Console. log (undefined = 0) // false
Console. log (undefined = '') // false
Console. log (undefined = NaN) // false
Console. log (0 = '') // true
Console. log (0 = NaN) // false
For "=", the following conclusions are drawn:
False: in addition to being true, and 0, ''is true.
Null is true only when compared with undefined. In turn, undefined is true only when compared with null.
The value of 0 is true in addition to false. There is also an empty string''
The Null String ''is true when it is outputted and false, and there is a number 0.