Boolean() 函数
Boolean(布尔)对象用于将非布尔值转换为布尔值。
- 0和nan,false
- 空串,false
- null和undefined false
- 空数组,空对象,空格字符串,都是true
console.log(Boolean(0)); // false
console.log(Boolean(NaN)); // false
console.log(Boolean(12)); // true
console.log(Boolean('')); // false
console.log(Boolean(' ')); // true
console.log(Boolean('小白')); // true
console.log(Boolean(null)); // false
console.log(Boolean(undefined)); // false
console.log(Boolean([])); //true
console.log(Boolean([1, 2, 3])); //true
console.log(Boolean({})); //true
console.log(Boolean({name:'why'})); //true
网友评论