Typically requires true and false judgments in the following statement structure
- if branch statement
- while loop
- for in the second statement
Such as
1
2
3
4
5
6
7
|
if
(boo) {
// do something
}
while
(boo) {
// do something
}
|
JavaScript has six is "false", this value is six
- false
- null
- undefined
- 0
- '' (The empty string)
- NaN
There is false in itself is a Boolean type, the other five are not.
In addition to these six, the others are "true", including an object, an array, canonical, functions and the like. Note that '0', 'null', 'false', {}, [] are also true value.
Although these six values is "false", they are not all equally between
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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
== == ==undefined )
// false
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
console.log (NaN == NaN) // false
|
For the "==", more than draw the following conclusions
- In addition to false and compare their outer true, and 0, "" Comparison is also true
- null and undefined only comparison is true, in turn, is only undefined and null comparison is true, there is no second
- In addition to 0 and false comparison is true, there is an empty string '' and the empty array []
- Empty string '' and in addition to false comparison is true, there is a number 0 false
- NaN is not equal and who compare themselves included.