I'm reading the book "You don't know JS" and I read this part:
What the author means here is that these foo functions will be hoisted at the global level since conditional statements don't have the ability to create their own scope in JS. So the expected behavior is that I will get b printed.
However the result is an error: "Uncaught TypeError: foo is not a function at :1:1"
However if I do this:
var a = true;
if (a) {
function foo() { console.log( "a" ); }
}
else {
function foo() { console.log( "b" ); }
}
and then invoke the function I will get the result "a"?