What I've heard is that Javascript engines are required to adhere to the rule
"If there's nothing to do, check the queue. But only check the queue if there's nothing to do."
and "the queue" is a queue of callback functions for asynchronous tasks. These are tasks that do not depend on the synchronous tasks and so they can be executed in parallel if the machine supports that. Let's say I have
SyncFunction1();
AsyncFunction1();
SyncFunction2();
AsyncFunction2();
Then order of execution is
Run SyncFunction1
Run SyncFunction2
Run callbacks of AsyncFunction1 and AsyncFuntion2
and whether the callback for AsyncFunction1
or AsyncFunction2
runs first depends on which task finished first. Is that correct?