1.使用 Boolean()函数来讲其他类型转换为布尔值
转换的情况:
数字:
- 0 和 NaN 转换为 false
其余是 true
字符串:
空串 转换为 false
其余是 true
null 和 undefine 都转换为 false
对象:对象会转换为 true
所有表示空性的没有错误的值都会转换为 false:
0 、NaN、空串、null、undefined、false
转换的情况:
数字:
- 0 和 NaN 转换为 false
其余是 true
字符串:
空串 转换为 false
其余是 true
null 和 undefine 都转换为 false
对象:对象会转换为 true
所有表示空性的没有错误的值都会转换为 false:
0 、NaN、空串、null、undefined、false