据我所知,以下声明不会为变量添加任何值aa:
var aa = undefined;
function a () {
var aa;
console.log(aa); // here aa is still undefined
if(!aa) {
aa = 11; // should add to the globle scope (window Object)
bb = 12; // should add to the globle scope (window Object)
}
console.log(aa);
console.log(aa); // should be 11
console.log(bb); // should be 12
}
现在,如果我想使用访问 varsaa和bb,我只能访问bbnot aa。我的问题是为什么aa不能从外部访问,因为在声明中我没有为它分配任何值并且它仍然是未定义的?
谢谢你。