Microtasks — Complete Guide
Microtasks — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of JavaScript Tutorial on Toolliyo Academy.
On this page
JavaScript Tutorial · Lesson 48 of 100
Microtasks
Basics ✓ → Objects & data ✓ → Async & DOM → Advanced → Tools → Projects
Intermediate · 3 — Async & DOM · ~6 min · JS Async JavaScript
What is this?
Microtasks are short jobs queued by promises and queueMicrotask. They run after the current script and before the next paint or macrotask.
Why should you care?
Explains promise callback ordering vs setTimeout.
See it live — copy this example
Paste into an HTML file or the browser console (F12). Use Run below when the live editor is available.
queueMicrotask(() => console.log("micro"));
Promise.resolve().then(() => console.log("promise"));
console.log("sync");
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- Sync runs first, then all microtasks in order, then macrotasks like timers.
Practice next
- Run sync / promise / queueMicrotask example.
- Predict order then verify in console.
- Compare with setTimeout(0) in same script.
- Chain three .then calls and log each step number.
- Schedule queueMicrotask inside another microtask and observe nesting order.
Remember
Promises use microtask queue Run before next macrotask Keep handlers fast
ScriptVerse state flush
A microtask queue flushes batched DOM updates after promise-based data normalization completes.
Outcome: Knowing microtask timing explains why UI sometimes updates before paint.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!