Skip to solution
mediumFrontend

What is a Promise and what are its states?

922 views
01

Understand the problem

Question presented to candidate: "If a Promise's executor function calls resolve() and then, a moment later, calls reject() as well — what actually happens? Does the Promise genuinely change from fulfilled to rejected?"

What a strong answer should cover:

  • 📌 Interview term: the three Promise statespending (not yet settled), fulfilled (completed successfully, with a value), and rejected (failed, with a reason) — every Promise starts pending and can transition to exactly one of the other two states.
  • 📌 Interview term: the real, direct answer to the prompt — verified directly: once a Promise is settled (fulfilled or rejected), its state is genuinely permanent — calling resolve/reject again afterward is genuinely a no-op, silently ignored. A Promise resolved first with "first value" and then immediately resolved again with a different value genuinely keeps the FIRST value — the second call has zero effect.
  • 📌 Interview term: .then() always returns a NEW Promise — verified directly: chaining .then() genuinely never returns the same Promise object — this is exactly the real mechanism that makes Promise chaining work at all.
  • 📌 Interview term: a thrown error inside .then() produces a rejected Promise — verified directly: throwing inside a .then() callback genuinely does NOT crash the program — it genuinely produces a rejected Promise, catchable by a .catch() further down the chain.
  • A precise answer names that resolving a Promise WITH another Promise (or any "thenable") genuinely flattens/unwraps it rather than nesting — verified directly, resolving with an already-resolved inner Promise genuinely produces the inner Promise's own real value, not a Promise-wrapped-in-a-Promise.

Clarifying questions expected:

  • None — this is a definitional/technical question; directly answering the prompt's own resolve-then-reject scenario (state permanence) is the strong signal.

Code / implementation expected: Yes — a real Promise where resolve is called twice (with a second, different value) is the clearest, most convincing demonstration of state permanence.

promises
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals/async interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every state-transition claim below was actually run in Node.

1. Why This Even M

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: a Promise's settlement is genuinely permanent — a second resolve() call has zero effect, and .then() always returns a new Promise
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 60 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track