为false的情况:
- false
- 0
- 0.0
- null
- NaN
- undefined
- ‘’
注意:所有的引用类型转为布尔类型都为true
执行代码:
<script>
// boolean 类型中只有true和false
// 转为false的情况
console.log(Boolean(false));
console.log(Boolean(0));
console.log(Boolean(0.0));
console.log(Boolean(''));
console.log(Boolean(undefined));
console.log(Boolean(null));
console.log(Boolean([])); // 空数组为true
console.log(Boolean({})); // 空对象为true 函数数组和对象(引用类型)永远为true
console.log(Boolean('0')); // true
console.log(Boolean(NaN));
console.log(Boolean(1)); // true
console.log(Boolean(Infinity)); // true
console.log(Boolean(-Infinity)); // true
</script>