I m actually studying different part of the event loop in javascript and I'm stuck understanding the execution order of the tasks from the task queue and the different microtasks.

For now, running the following script in node / chrome:

setTimeout(() => console.log("setTimeout callback"), 0);
Promise.resolve().then(() => console.log("Promise callback"));

Gives me the following result (in order):

  • Promise callback
  • setTimeout callback

The information I'm taking from this is:

  • All of the microtasks are executed right before the next task in the loop.

My problem is: from Jake Archibald, a great software engineer working on different specs, in his article dealing with microtasks and the event loop explains that:

The microtask queue is processed after callbacks as long as no other JavaScript is mid-execution, and at the end of each task

Can anybody highlight me with this?

  • 1
    The article you linked comes up with the same results as you did, and explains why in great detail. – Robert Harvey Oct 24 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.