DEV Community

Discussion on: Improve your JavaScript code with these...

Collapse
 
psiho profile image
Mirko Vukušić • Edited

I don't think it's true that .map() and similar are faster than "traditional" loops. It's just more readable. However, difference is insignificant most of the time. But if you have a realy large array that you're iterating over, then do it un for loop.

As for comments... It's subjective, but I like "clean code" virw on this and like the code that does not need comments at all. So write descriptive variable/function names, break functionality in smaller parts, use readable code and avoid comments unless neccessary.

EDIT: to be more precise, map() was just an example but I was referring to all "new features to make our life easier". So in general, traditional loops are faster, but of course not always, faster than filter(), foreach(), etc. Not for your exact use case above. In example check: jsbench.me/5fizlui8g7