Joel Thoms
Jul 28, 2017 · 1 min read

It likely depends on which JavaScript engine, the engine version and your specific application.

Check out this recent comment from another article:

I guess the Mozilla developers heard you. Just did a little js-perf fiddle to retest and now forEach is roughly 20% faster than a traditional for loop (including length caching). :D — Johannes Rebhan

Unless you have identified this piece of your code as a bottleneck, it is not recommended to micro-optimize. Especially since your “optimizations” might be unoptimized with future JavaScript engine updates.

This is a great video by Mattias Petter Johansson that explains why this is not important.

You could also use a library that has optimized for performance so you do not have to. I would recommend lazy.js, it’s a great lib.

Cheers!

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade