【发布时间】:2014-01-28 22:58:30
【问题描述】:
这里
var a = {}
什么时候
if(typeof a.b == "undefined"){
console.log("undefined");
}
if (!a.b){
console.log("undefined");
}
两者都返回"undefined"
以及何时
if(typeof c.b == "undefined"){
console.log("undefined");
}
if (!c.b){
console.log("undefined");
}
两者都引发错误c is not defined
上面的 2 个 if-else 语句看起来是一样的。那么哪种方式更好呢?
【问题讨论】:
标签: javascript performance undefined