0
Const variables in a for loop
Hello Everyone... Can someone explain this piece of code please..... for (let i=0;i<10;i++){ const z =i console.log (z) } Why aren't we getting any errors?... Aren't we declaring a const again?
2 odpowiedzi
+ 2
const variables are block-scoped so the lifetime of z ends at the end of every iteration, allowing const z to be redeclared in the next iteration.
0
jtrh thanks i got it 🌹