1

The Javascript engine is executing a function which in turn calls another function (sequentially) and this goes on for say 5s. Meanwhile, several events were triggered either by the user or programmatically.

Can we take for granted that no event will be handled before the outermost function finishes?

/* Example */

function outermost_function() {
 function inner_function () {
  function innermost_function () {
    return;
  }
 }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
utxeee
  • 953
  • 1
  • 12
  • 24
  • Why is this tagged `async`/`await`? Are those functions "that in turns call each other" asynchronous or not? That would make a huge difference. – Bergi Dec 09 '16 at 13:20
  • Hi @Bergi, to be honest the answer is not clear enough, I will change it accordingly. – utxeee Dec 09 '16 at 14:08
  • Sorry, it is not the answer but the question ! – utxeee Dec 09 '16 at 15:28

1 Answers1

3

Javascript is single threaded and events are queued in an event loop. JS code does not execute in parallel on the main thread. Code on the main thread is never interrupted.

That being said, it is possible to execute code in parallel with the use of web workers.

There are many excellent articles on the subject of the Javascript event loop, I would recommend starting here

George Lee
  • 826
  • 6
  • 11