0Pricing
JavaScript Academy · Lesson

Event Loop & Task vs Microtask Basics

See how the event loop runs sync code first, then microtasks, then tasks. Practice with setTimeout, Promise.then, and queueMicrotask.

Intro to event loop

Goal: Learn the basic order: sync code → microtasks (Promise/queueMicrotask) → tasks (setTimeout).

  • Sync first
  • Microtasks next
  • Tasks last
Event Loop & Task vs Microtask Basics — illustration 1

Sync first

Synchronous statements execute top-to-bottom before any queued callbacks.

// Sync code runs immediately
console.log("A: sync start");

console.log("B: sync middle");

console.log("C: sync end");
Event Loop & Task vs Microtask Basics — illustration 2

All lessons in this course

  1. Event Loop & Task vs Microtask Basics
  2. Promises — States, Chaining, Error Handling
  3. Promise.all / any / race / allSettled — choose the right tool
← Back to JavaScript Academy