Open jamesongamble opened 9 years ago
Not sure I follow. While it is true that these i
instances are in the same scope, and the second one strictly does not need to be declared, what can be the problem if it's initialised ?
The place this kind of thing might cause problems is in reentrant code using a parent scope variable, or where the var
keyword is forgotten and a global i
is declared, which can definitely be unexpectedly changed at random times elsewhere. This case is neither of those.
The second for loop in this example script reinitializes the variable i. Weird looping bugs may arise later with bigger arrays. As such, I have set the second loop to start at var j.
Before:
After: