In the code below, is ele available only for an individual iteration of the loop?
for (var i=0; i<3; i++){
const ele = i
console.log(ele)
}
I'm thinking this should be the case, otherwise there will be a
Syntax Error: Identifier 'ele' has already been declared
every time the loop iterates after the very first time.
I could not find a way to confirm this using console.log(), so looking for a concrete answer.
EDIT: To clarify, I understand that ele is valid within the for loop only. My question is specifically if the scope is ' reinstantiated' every iteration of this loop or not. It definitely looks like it, but I haven't heard or read that explicitly anywhere yet.
eleis updated on each iteration, not just the first. And each iteration will get a new instance ofeleas a new block is created each loop.{const x=1; {const x=2; { const x = 3; }}}as eachconst xis in a separate block scope. IOW whenever you see code inside{}including for loops, you have a new block scope.