2 ms·
12 if you count the declaration. You'd have exactly the same doing it yourself, you can at most reduce it to 10 by declaring i and ln inside for(). You're also
by ricardobeat 15y ago
12 if you count the declaration. You'd have exactly the same doing it yourself, you can at most reduce it to 10 by declaring i and ln inside for().
You're also overlooking the fact that this can be considered an advantage: variable naming for these transient uses is very consistent. When writing JS you could have names all over, even a different one for every loop.
- johnbender 15y agoI've maintained the hoisted index variable and cached the length: var i, foods = ['toast', 'cheese', 'wine'], foods_length = foods.length; for (i = 0; i < foods_length; i++) { eat(food[i]); } Prefixing variables with an underscore is not an advantage in readability because it lends nothing to the description of what the variable represents. Its another glyph that you have to visually parse before reaching possible meaning.
- ricardobeat 15y agoI didn't say the underscore is good - it's a necessary evil. I said consistency is good. And you just proved my point.