← All threads

The Javascript .forEach method - blog

2 of Michael's comments in this thread · View thread on Reddit ↗

u/michaelnovati replied ·
Some followup ideas: 1. For loop vs a foreach and what the similarities differences are in super detail (i.e. the differences between passing a callback function and having an inline function 2. Async/await and order of operations inside a forEach

u/Sad-Brief-2846 wrote (the comment Michael replied to):

u/michaelnovati \- could you please give me examples of what you consider inline and callback functions? just to see if I have a correct idea of the difference

u/michaelnovati replied ·
Passing in a function is subtly different "scope" then when a for loop is in the same scope as the parent context In most cases you won't see much impact, but you can rig up some examples where it matters. There is also for x of n that you can compare to too. There are subtle performance implications of all of these that is a few levels more deep as well