Skip to content

Instantly share code, notes, and snippets.

@KiranMantha
Last active January 20, 2026 06:16
Show Gist options
  • Select an option

  • Save KiranMantha/8584bb50293e417c441d2c0792309026 to your computer and use it in GitHub Desktop.

Select an option

Save KiranMantha/8584bb50293e417c441d2c0792309026 to your computer and use it in GitHub Desktop.
Javascript code execution priority

JavaScript doesn’t just run code in order — it maintains multiple queues with different priorities:

  • Call Stack: Currently executing code (highest priority)
  • Microtask Queue: Promises, queueMicrotask, MutationObserver
  • Macrotask Queue: setTimeout, setInterval, I/O, UI events
  • Render Queue: requestAnimationFrame, style/layout/paint
console.log('1: Sync');
setTimeout(() => console.log('2: Macro'), 0);
Promise.resolve()
  .then(() => console.log('3: Micro 1'))
  .then(() => console.log('4: Micro 2'));
requestAnimationFrame(() => console.log('5: RAF'));
console.log('6: Sync');

// Output: 1, 6, 3, 4, 5, 2
// Sync → All Micros → RAF → Macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment