The constant defined by const is variable in the for loop.

for(let a = 1; a < 5; aPP){
    const b = a;
    console.log(b) // 1 2 3 4 undefined
}

Why for can const be reassigned within the loop?

Thank you!

May.22,2021

when the for loop ends, the life cycle of constant b ends. In the next for cycle, a new constant b


block scope and life cycle

is added.
Menu