Similar to This Question, what are the advantages of using const inside js for loops instead of let and var for values that change each iteration?
I am not a particular fan of this pattern, but I am interested in learning about the advantages of this pattern.
Background
When I write JavaScript in Visual Studio and type for it suggests the following code block:
for (let index = 0; index < array.length; index++) {
const element = array[index];
}
I personally am not a fan of this pattern as reassigning a value to a const each iteration as it seems to violate the core idea of a constant ( yes, I know the constant technically goes out of scope, but it still feels like a const is being assigned a new value).
I assume there must be many good reasons for this pattern, otherwise why would this stick around as a suggested code block. I have come up with a good reason, but I am still curious about what advantages I am missing.
Reason I came up with
I could see this being useful within a large code block where you either need to ensure no one uses this name or this name is referenced multiple times expecting the same value.