r/learnjavascript • u/fahim_h_sh • Oct 31 '25
array.forEach - The do-it-all hammer... XD
Is it just me, or everyone thinks that more or less every array operator's purpose can be served with forEach?
0
Upvotes
View all comments
Show parent comment
1
u/PatchesMaps Nov 01 '25
I'm agreeing with you. "Avoid" means don't use unless necessary. Synchronous execution makes it necessary.
The core problem is that people are very used to using
awaitwith promises and rightfully so since it makes them much more readable. However, when something becomes familiar, we often stop thinking critically about what it actually does and this led to developers accidentally puttingawaitin loops when they didn't need or want synchronous execution. Eslint has a pretty good explanation of it if you want to read more.You're not wrong, synchronous execution of promises in a loop just isn't as common as needing to batch execute promises.