Lesson overview · Free interview practice

Promise Patterns

Master advanced Promise patterns and asynchronous flow control.

Topics in the full lesson
  • Introduction to Promises
  • Creating Promises
  • Handling Promises
  • Promise.all and Promise.race
  • Asynchronous Patterns
  • Best Practices
  • Exercises

Try the free interview questions

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

TheoryMedium

`Promise.withResolvers` and the Deferred Pattern

Question

What does Promise.withResolvers() return, and what problem does it solve? Show the deferred pattern with and without it.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

TheoryMedium

Promise Anti-Patterns Catalog

Question

What are the most common Promise anti-patterns, and what does the correct code look like in each case?

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

TheoryHard

Timeout and Retry-with-Backoff Patterns

Question

Implement a withTimeout(promise, ms) helper and a retry(fn, options) helper with exponential backoff. What edge cases do production implementations need to handle?

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

TheoryHard

Cancellation with `AbortController` and `AbortSignal`

Question

How do you cancel an in-flight async operation with AbortController and AbortSignal? Show integration with fetch, signal composition, and how to adapt non-aware APIs.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

TheoryHard

Promise Execution Semantics + the Microtask Queue

Question

When does a .then callback actually run relative to surrounding code? Walk through the microtask queue and how await desugars to a microtask checkpoint.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

TheoryHard

Implement a Promise from Scratch (A+ State Machine)

Question

Implement a MyPromise class whose then method follows the Promises/A+ state machine: a promise starts pending and transitions once to fulfilled or rejected; then callbacks run asynchronously (on the microtask queue) and must chain; and a handler that returns another promise is adopted.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Promise Patterns material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium