> it's useless to define a var inside a loop
No, `for` loops have nothing to do with JavaScript scope. What you probably ran into was a situation like this:
for (var i = 0; i < length; i++) {
do blah;
}
for (var i = 0; i < length; i++) {
do more blah;
}
In this case, as a stylistic preference, JSLint will suggest you remove the second var, or you can also declare it at the top of the scope and then omit the var declarations in the `for` loops anyway.And yes, strictly speaking, the latter option is the most performance-oriented, although most JS interpreters optimize for this not anyway such that it makes no difference.
But this JSLint suggestion really has nothing to do with the `for` loop, this situation would have the same effect:
var i = 0;
i++;
use(i);
var i = 0;
i++;
use(i);
`for` loops have no impact on scope, which is mostly functional, with some prototypical complexities thrown in for good measure.