If we put function declaration inside for
loop — its name will be hoisted, but it will contain undefined
:
console.log(foo, bar); //undefined function bar() {}
for (var i = 0; i < 1; i++) {
function foo() {}
}
function bar() {};
Why is it like that? It is told everywhere that var
gets hoisted, leaving initialization in place, and that function declarations are fully hoisted. Seems like some specification quirk but it is curious why it works this way