涉及原理:隐式转换,if()是布尔转换,相对等于==是Number转换
- 判断是否为空 Object(空对象)
JSON.stringify(a) === '{}',如果a是一个空对象则为true,如果a是有值的对象则为false
- 判断是否为空 Array(空数组)
a.length=== 0,如果a是一个空数组则为true,如果a是有值的则为false
- 其他情况
if(a){} //undefined,null,0,-0,NaN,"",'' 结果为 false,空数组和空对象都是object,为true
- null与undefined的区别?具体点击此处
console.log(null==undefined)//true
console.log(null===undefined)//false
alert(typeof undefined); //output "undefined"
alert(typeof null); //output "object"