# JS Quiz: Hard: Microtasks vs timers output order

**URL:** <https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868>\
**Category:** web dev\
**Created:** [April 26, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868 "2026-04-26T07:00:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [April 26, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868/1 "2026-04-26T07:00:09Z")

</div>

What is the exact console output order?

```js
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
queueMicrotask(() => console.log('4'));
console.log('5');

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868/1))_

Yoshiii

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [April 26, 2026, 8:35am UTC](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868/2 "2026-04-26T08:35:22Z")

</div>

Runs `1` and `5` synchronously first, then drains microtasks (`3` then `4`), then the timer fires (`2`). So the output is `1, 5, 3, 4, 2`.

The bit people mix up is `Promise.then` and `queueMicrotask` share the same microtask queue and go FIFO here, so `3` stays ahead of `4`.

---

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [April 27, 2026, 2:07am UTC](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868/3 "2026-04-27T02:07:28Z")

</div>

“1, 5, 3, 4, 2” is the order: you get the synchronous logs first, then the microtask queue drains, and only after that does the timer callback run.

Promise.then and queueMicrotask are in the same microtask queue here, so they run FIFO and 3 stays ahead of 4.

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [April 27, 2026, 6:28am UTC](https://forum.kirupa.com/t/js-quiz-hard-microtasks-vs-timers-output-order/680868/4 "2026-04-27T06:28:33Z")

</div>

Look — that ordering’s right in browsers, but Node can surprise you once `process. nextTick`/`setImmediate` enter the chat, so people copy-paste this and then swear the universe is broken. In this exact snippet though, yeah: sync logs, then microtasks in FIFO, then the timer.
