Back to search

Event loop, Web APIs, callback queue, microtask queue, macrotask queue, promise queue, and setTimeout behavior

JavaScript's event loop decides when queued async work can return to the call stack, with microtasks running before the next macrotask.

JavaScript Hard Theory

Event loop, Web APIs, callback queue, microtask queue, macrotask queue, promise queue, and setTimeout behavior

JavaScript's event loop decides when queued async work can return to the call stack, with microtasks running before the next macrotask.

  • The stack must be empty before queued work runs
  • Promise callbacks go to the microtask queue
  • `setTimeout` is a minimum delay, not an exact execution time

Event loop, Web APIs, callback queue, microtask queue, macrotask queue, promise queue, and setTimeout behavior