0

In node.js.

Is Array.forEach may let other contexts to be executed before executing all elements?

How actually it works ?

I know that (correct me if something wrong please):

  • The top execution context in the call stack is the context that will be executed first.
  • No two execution contexts are executed at the same time.

Is that mean: - If we use loop such as (for .. in ..) there is no other execution context will be executed until the entire loop is executed and if we use forEach (which I think is creating an execution context for each element) may let other contexts that may be added by the browser for Ajax or by node.js for finished I/O operation to the call stack to be executed before the executing the callbacks for each element ?

faressoft
  • 19,053
  • 44
  • 104
  • 146
  • 2
    Node.js is single-threaded. There is no concurrency. – user229044 Apr 20 '16 at 21:59
  • 3
    "(which I think is creating an execution context for each element)" It is not. [This question](http://stackoverflow.com/questions/5050265/javascript-node-js-is-array-foreach-asynchronous?rq=1) might clear things up. – E_net4 Apr 20 '16 at 22:01
  • Also have a look at [Are all Node.js callback functions asynchronous?](http://stackoverflow.com/q/21884258/1048572) – Bergi Apr 21 '16 at 00:51

0 Answers0