我只是在尝试这个 JS 代码 -
if(a){
console.log("a IS DEFINED")
} else {
console.log("a IS UNDEFINED")
}
我收到错误 -
ReferenceError: a is not defined
但是当我添加var a
它时a IS UNDEFINED
var a;
if(a){
console.log("a IS DEFINED")
} else {
console.log("a IS UNDEFINED")
}
// prints a IS UNDEFINED
为什么在这两种情况下它的行为a
不同undefined
?