While loops in JavaScript
Flynn Buckingham
82

You must be doing something really esoteric if the amount of time spent on declaring let variables inside a loop is significant.

I’d also caution against reading much into that JSPerf you linked. I ran the tests on FF57. 8 of the results clustered so closely together that I suspect we’re actually measuring how long JSPerf takes to bootstrap each run, and not how quick the loops are. Given Chrome’s results (at least for 60+) I suspect the same thing is true for the V8 crowd.

Regardless, the only real stinker is the for..in loop — which is understandable since you shouldn’t be using for..in to iterate an array to begin with!

I think my recommendation still stands: use the loop that most clearly communicates your intention to your fellow humans, and let the interpreter take care of the details. (Well, unless you like using for..in on arrays, in which case just don’t; really.)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.