总结
公式
function test(a){
if(a){
console.log(true);
}else{
console.log(false)
}
}
验证
- undefined
// undefined
var a;
typeof a;
test(a);
- string
//空字符串 注意:如果引号中含有空格则为true。
a = "";
typeof a;
test(a);
3. number
// 注 0字符串对应的为true
a = 0;
typeof a;
test(a);
test(NaN);
4.object
a = null;
typeof a;
test(a);
5.boolean
a = false;
typeof a;
test(a);