I am reading YDNJS: scope and closures, And in chapter 4 which talks about hoisting it says that
Function declarations that appear inside of normal blocks typically hoist to the enclosing scope, rather than being conditional as this code implies
foo(); // "b"
var a = true;
if (a) {
function foo() { console.log("a"); }
}
else {
function foo() { console.log("b"); }
}
the author assumes that foo() will print 3 to console as the last function declaration override the previous one in the if block before the engine evaluates the condition.
The problem is that when I run this code on my own it throws a TypeError: foo is not a function instead of 3.