queueMicrotask vs setTimeout Playground

Four orders at the warung: console.log, queueMicrotask, .then and setTimeout(0), each scheduled its own way; guess the order, then the browser prints the four…

Why it matters

Guessing this order wrong breeds the most confusing async bugs: state updated "late", logs in a strange order, a frozen page. Knowing "every microtask is drained before one task" explains almost every timing surprise in JavaScript, and when queueMicrotask starves the task queue instead.

The key idea

Every microtask is drained before a single task runs

Common mistakes

Try it in this playground