I have this code with function declaration and addittional block statement who's make new lexical environment:
console.log("1:"+foo);
{
console.log("2:"+foo);
function foo(){ console.log("checked"); }
console.log("3:"+foo);
}
console.log("4:"+foo);
Why first log output undefined
?
Yes, the function is hoisted. But it's unclear why inside the block statement we get this function before the declaration and after the declaration, but outside the block before the declaration we get undefined.
I would like to get an explanation from the point of view of the specification.