I've been asked about a question
{
function foo() {
console.log('A');
}
foo();
foo = 1;
function foo() {
console.log('B');
}
foo = 2;
console.log(foo);
}
console.log(foo);
Why the third output is 1 instead of 2?
There should be no block scoped foo being created since there is neither let nor const in that block. But the second foo output is 2 means there is indeed another reference of foo has been created.
What is going on?
P.S. I'm using Chrome
Version 89.0.4389.90 (Official Build) (x86_64).