JS Built-ins
AsyncPatternsintermediate

Promise.then callbacks are asynchronous (microtask)

πŸ“– Usage Example
let x = 0;
Promise.resolve().then(() => { x = 1; });
// x is still 0 here β€” .then runs as a microtask

.then callbacks are microtasks β€” they run after synchronous code completes.

Microtask Queue

.then() callbacks are executed asynchronously as microtasks. They run after synchronous code but before macrotasks.

Challenge: Verify that a .then callback does not run synchronously.

πŸ’‘ Hints (3)
  • β€’ .then callbacks are microtasks, not synchronous.
  • β€’ They queue after the current execution context.
  • β€’ This is key to understanding the Promise execution model.