How do promises work? Explain their states and chaining.
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
A promise is an object representing an eventual value with three states: pending, fulfilled, rejected. Once settled it never changes. .then chains transform values; .catch handles any failure in the chain; .finally always runs.
Detailed explanation
A promise starts pending and settles exactly once — to fulfilled with a value or rejected with a reason. Handlers registered via .then(onFulfilled, onRejected) are guaranteed to fire asynchronously regardless of when settlement happens, avoiding the race conditions of older callback APIs. Every .then returns a new promise, enabling flat chains instead of nested callbacks; returning a plain value resolves the next link, while returning another promise makes the chain wait for it. Errors propagate down the chain until a .catch catches them — like try/catch across time. Static helpers compose sets: Promise.all fails fast on first rejection, Promise.allSettled waits for every outcome, Promise.race settles with the first settled, and Promise.any resolves with the first success. Common pitfall: forgetting to return inside .then breaks value flow silently.
Example
fetchUser(1)
.then(user => loadProfile(user.id)) // return = chain continues
.then(profile => render(profile))
.catch(err => showError(err)) // catches either step
.finally(() => hideSpinner());
Promise.all([api.users(), api.posts()])
.then(([users, posts]) => dashboard(users, posts));Interview tip
Say 'settles exactly once' early — it's the phrase interviewers listen for. Then contrast Promise.all vs allSettled with a parallel-fetch example.
Common mistakes
- Forgetting to return promises inside then callbacks.
- Saying a settled promise can be re-resolved later.