Michael Helgesen1,140 Points
The var in for loop
Hi folks. Greetings from Norway. Total noob here trying to hang on with these loops. This may be a stupid question, but I would love to hear an explanation. I hope that helps me to learn better :)
My question is about the var in the for loop: for (var i = 0; i < 10; i += 1)
Why cant it be just like this: for (i = 0; i < 10; i += 1)
Thanks so much!
That's why I say that it might very well work, but why chance it? Does that make any sense?
james southFront End Web Development Techdegree Graduate 33,249 Points
i is a variable like any other and must be declared. you can also use let.