There below two codes print different outputs, despite the inner function not being called.
var a = 1;
function foo(){
a= 2;
}
foo();
console.log(a); // 2
But if I add a function with the same name, the output is different. Although I am not calling the a()
var a = 1;
function foo(){
a= 2;
function a(){
a = 3;
}
}
foo();
console.log(a); // 1
Should not it be 2? Why it logs 1?