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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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
- What is a promise and what are its states?
- Is the executor sync or async? Predict a snippet.
- What happens if you call resolve twice, or reject after resolve?
- Why are promises better than callbacks?
- What is the difference between resolved and fulfilled? Is Promise.resolve(p) === p?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.