#DailyBloggingChallenge (62/100)
#TIL that the convenience that one gets using forEach
do not outweigh the performance lost.
In comparison the standard for
-loop within #JavaScript performs the most(*) operations per second and forEach
the least (Source). *: To squeeze even more performance one should cache the length of the array.
Further it should be considered to convert all other for
operators like for... in
or for... of
to the standard for
-loop.
Although these performance differences matter when iterating through larger numbers. Thus, one could argue on the smaller scale that the convenience makes sense. Though this could harden bad #coding practices for the future.
@Neblib @barefootstache This!
@barefootstache while it's true that you'll get performance benefits, readability and consistency are factors to consider that might change whether other forms should be considered "bad" coding practices. For example, if you are working on a team that likes functional programming, the switch to iterative formats would likely be jarring to following the code flow. Always be wary of premature optimization.