Follow

(62/100)

that the convenience that one gets using forEach do not outweigh the performance lost.

In comparison the standard for-loop within 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 practices for the future.

@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.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.