I am learning javascript
hoisting feature, and find the following codes are really confusing:
var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
alert(a);
The output is 1
. As far as I know, because of hoisting
, the codes above are equivalent to
var a;
function b() {
function a() {}
a=10;
return;
}
a=1;
b();
alert(a);
What happens when a function
and a variable
has the same name a
?