I thought all functions and their bodies got hoisted. I did this test:
foo();
var blah = true;
if (!blah) function foo() { console.log('falsy') }
else function foo() { console.log('truthy') }
And I get that foo
is not a function. It seems its making foo
a variable and its declaration got hoisted. But it doesn't get initialized till the if
statement.
I was surprised by two things:
- The last
function foo
didn't get its body hoisted - I didn't see
ReferenceError: foo is not defined
but instead i sawTypeError: foo is not a function