const todolist= []; let todolisthtml = ''; for(let i =0;i<todolist.length;i++){ const todo = todolist[i]; const html = <p>`${todo}`</p>; todolisthtml += html; }
Here, whenever we iterate through the loop, we are reassigning the variable todo, which should cause an error because we declared it using "const", but it works smoothly
This is not a task. Just declaration and initialization.
If you write
This would be a reallocation and is illegal.
In what you wrote,
todo
andhtml
go out of scope at the end of the loop block, followed by a newtodo
andhtml
is created for the next iteration.As Jaromanda X said,
const
variables are block scoped. Andlet
.