将其他的数据类型转换为 Boolean
- 使用 Boolean() 函数
- 数字 ---> 布尔
除了 0 和 NaN, 其余都是 true;
- 字符串 ---> 布尔
除了空串 "", 其余都是 true; 空串里加空格也是 ture;
-null 和 undefined 都会转换为 false;
- 对象也会转换为 ture;
- var a="123";
- a=Boolean(a);
- console.log(typeof a);
- console.log(a);
输出结是为 true;
来源: http://www.qdfuns.com/article/17043/654a70102c1a4f8db34c9ff4ac4dd065.html