Boolean Boolean data type
Only words denomination; true and false, the digital value two values are not the same, and therefore does not necessarily mean a true and false is not necessarily equal to zero.
To convert to other types of Boolean type
Only 0, NaN, '', null, undefined five values are converted to false, the rest are converted to true (but without any special circumstances)
type of data | Converted to true values | Converted to a value of false |
---|---|---|
Boolean | true | false |
String | Any non-null string | "" Empty string |
Number | Any nonzero numeric value (including infinite) | 0 sum NaN |
Object | Any object | null |
Undefined | Not applicable | undefined |
Boolean(true) // true
Boolean(false) // false
Boolean('Hello Wolrd') // true
Boolean() // false
Boolean('') // false
Boolean(' ') // true (里面有空格)
Boolean(1) // true
Boolean(0) // false
Boolean(NaN) // false
Boolean({}) // true
Boolean([]) // true
Boolean(null) // false
Boolean(undefined) // false
To convert to other types of Boolean type in three ways:
Boolean()
!
Or!!
inverted: first converted to boolean, and then negated- Conditional