I have a small question about for loop in Js: Why i have to write:
for (let i; i < 10; i++) {}
Meanwhile, the code will run correctly if i write:
for (i; i < 10; i++) {}
Thanks for your answer!
I have a small question about for loop in Js: Why i have to write:
for (let i; i < 10; i++) {}
Meanwhile, the code will run correctly if i write:
for (i; i < 10; i++) {}
Thanks for your answer!
 
    
    It works because JavaScript allows using undeclared variables. But if you enable strict mode using 'use strict', it will not work as you never declared i. It’s better to use the first example you provided.
