Skip to the page

Promises in depth · core

Promises: states, the executor and settling once

A promise is an object for a future result that starts pending and settles exactly once, to fulfilled with a value or rejected with a reason; the executor passed to new Promise runs synchronously, and handlers always run asynchronously as microtasks.

The notes

What you must know

  • States: pending -> fulfilled or rejected. 'Settled' means not pending. 'Resolved' is not the same as fulfilled: a promise resolved with a pending promise is locked to it and still pending.
  • The executor runs immediately and synchronously. Code after resolve() still runs. Later resolve or reject calls are ignored.
  • A throw inside the executor rejects the promise, unless it was already resolved.
  • then callbacks always run in a microtask, even if the promise is already settled.
  • Promise.resolve(v) returns v itself if v is a native promise and wraps anything else (thenables are followed). Promise.reject(r) always makes a new rejected promise.
  • Why promises beat callbacks: composition (chains, combinators), one result delivered once, errors that travel to a catch, and consistent async timing.
  • Promise.withResolvers() (ES2024) returns { promise, resolve, reject }, the 'deferred' pattern.

The red pen

Common traps: mistake → fix

  • Mistake: The executor runs asynchronously

    Fix: it runs synchronously, right away.

  • Mistake: resolve() stops the executor

    Fix: code after it still runs; use return.

  • Mistake: Resolving with another promise means fulfilled

    Fix: it follows that promise and may still reject.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is a promise and what are its states?
  2. Is the executor sync or async? Predict a snippet.
  3. What happens if you call resolve twice, or reject after resolve?
  4. Why are promises better than callbacks?
  5. What is the difference between resolved and fulfilled? Is Promise.resolve(p) === p?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview