Just a minor thing with a loop

I am asked to write a for loop to print numbers from 100 to 0 in steps of 10 like 100, 90, 80, …, 0. I did this:

for (let i=100; i>=0; i-=10) {

It worked OK and I was happy about it… But then, looking at the answer to the exercise provided by the author I ran into this:

for (i=100; i>=0; i-=10) {

It also worked fine but I was wondering why is it that the variable i doesn’t have to be declared in the solution given by the creator of this exercise.

Unless you’re running your JS in a ‘strict mode’ you can define a variable without a keyword.

1 Like

Thanks! That’s it… Run JS in strict mode…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.