I'm trying to understand exactly how does different declarations are being bound to Lexical Environment's Environment Record of block and function scope.
Consider the following code:
function myFunc() {
if(true) {
let first = "first";
const second = "second ";
var third = "third ";
function fourth() { }
}
console.log(first); // ReferenceError
console.log(second); // ReferenceError
console.log(third ); // "third"
console.log(fourth); // "function fourth.."
}
As for the var declaration, for my knowledge its being bound to the Environment Record of the Execution Context's VariableEnvironment component, which means the binding exists inside the Lexical Environment of the "myFunc" function.
But what about the declared function "fourth"?
Does the Lexical Environment of the if statement (Block Scope) creates some sort of a different Environment Record that only bounds let and const declarations?
Please refer to ECMAScript in your answer if possible.