JS类型转换
转化为false的值为
console.log(Boolean(0));
console.log(Boolean(''));
console.log(Boolean(NaN));
console.log(Boolean(undefined));
console.log(Boolean(null));
而像那些容易误导人的面试题目有
console.log(Boolean({}));
console.log(Boolean([]));
console.log(Boolean([0]));
console.log(Boolean('0'));
console.log(Boolean('false'));
console.log(Boolean([0].toString()));
只要不是以下特殊值,其余的都是转化为真true。
0
‘’null
undefinedNaN
当然如果你用布尔值 false 转布尔值的话那你是个狠人。