The JavaScript keyword `let` declares a block-scoped binding that can be reassigned. Its scope is the nearest enclosing block, such as a function body, an `if` statement, or a standalone pair of curly braces. section 7.3.1 section 7.6
Keep these rules in mind:
- A `for` loop’s initializer belongs to the loop’s scope, and each iteration creates a new scope. section 7.3.1
- A `let` binding cannot be accessed before its declaration executes; doing so throws a `ReferenceError` while the binding is in the temporal dead zone. section 7.3.2
Listing 7.5 Loop scope and closures
for (let i = 0; i < 3; i++) {
setTimeout(() => {
console.log(i);
}, 10);
}
In this timer example, each callback logs the value of `i` from the iteration that created it, rather than all callbacks sharing one final loop value. section 7.3.1




