I am studying javascript hoisting from Scope & Closures book one of You Don't Know Js books series, I understand how hoisting works but when it comes to this example it behaves in different way.
foo(); // "b"
var a = true;
if (a) {
function foo() { console.log( "a" ); }
}
else {
function foo() { console.log( "b" ); }
}
The book mentioned the Output supposed to be "b" due to the functions hoisting and overriding, But the result in my browser is this error.
Uncaught TypeError: foo is not a function
at <anonymous>:1:1
So what happened in this case to throw TypeError ?