It seems like a lot of people are talking around the real point of confusion here...
Ok, so when you say
// scope A
for(let i = 0; i<5; i++) {
//scope B
}
we know i
is not declared in Scope A. (That's one of the big problems let
solves.) So it seems it must be declared in Scope B. But what about this case?
// scope A
for(let i = 0; i<5; i++) console.log(i);
The for loop still has to have its own scope, in order to keep i
from being in Scope A. And we can demonstrate this.
let i = 37;
for(let i = 0; i < 5; i++) console.log(i);
console.log(i); // prints 37
Now if the for
statement already has a scope even though it has no braces, then what happens when we replace console.log(i)
with a block statement? Well, that block statement gets its own scope. So really we have
// Scope A
for( //scope B is actually here
let i = 0; i < 5; i++) {
// Scope C
}