Weird explanation in MDN Docs?

So here, they explain how the for...of loop works. And they essentially said that it takes the first element in fruits and sets that value to the fruit variable, then runs the JS code in the curly braces. The weird thing comes when this gets repeated for the second element. So the fruit variable gets re-initialized to the second element in fruits, but the problem is, fruit is a const, so how does this work? Any explanation to help understand this would be appreciated, thanks! 🙂
3 Replies
MarkBoots
MarkBoots•3y ago
const is block-scoped. everything within the { } is a block so it will just redeclare the variable
MarkBoots
MarkBoots•3y ago
const - JavaScript | MDN
Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration). However, if a constant is an object or array its properties or items can be updated or removed.
son arg
son argOP•3y ago
Thanks! 🙂
Want results from more Discord servers?
Add your server