As far as I know the following declaration will not add any value to the variable 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
}
Now if I want to use access the vars aa
and bb
, I can get access only bb
not aa
.
My question is why aa
cannot be accessed from outside, because in the declaration I haven't assigned any value to it and it is still undefined?
Thank you.