JS Built-ins
AsyncPatternsintermediate

Executor runs sync, then handler is async

πŸ“– Usage Example
let order = [];
new Promise(resolve => { order.push(1); resolve(); })
  .then(() => order.push(3));
order.push(2);
// order is [1, 2] β€” then handler has not run yet

The Promise executor runs synchronously; .then handlers run asynchronously.

Executor vs Then

The executor function runs synchronously, but .then() handlers run asynchronously as microtasks.

Challenge: Verify the execution order: executor sync, then handler async.

πŸ’‘ Hints (3)
  • β€’ The executor function runs synchronously.
  • β€’ .then() and .catch() handlers run asynchronously as microtasks.
  • β€’ Synchronous code after the Promise runs before microtask handlers.