Calling a function before its surrounding name declaration can behave differently depending on the declaration keyword. With var, the name exists as undefined; with let, accessing it before assignment throws an error. section 6.2.1
let makes execution order visible at the point of use: the binding cannot be successfully read until its declaration has initialized it. This avoids silently passing undefined into code that runs too early. section 6.2.1
Early access fails
greet(); let name = 'Sally'; function greet() { console.log(`Hello, ${name}`); } The call reaches name before its let declaration has initialized the binding, so execution throws instead of logging a greeting with undefined. section 6.2.1




