35 min·intermediate

Lesson 3

Promises

Build a practical mental model for promises and use it in working JavaScript.

By the end, you will be able to…

  • Explain promises in your own words
  • Use promises in a small program
  • Recognize and debug a common failure mode

Build the mental model

A Promise represents a value that isn't ready yet. It starts pending, then settles once to either fulfilled (resolve was called) or rejected (reject was called) — never both, and never more than once.

Syntax and working example

Read the code from inputs to output. Predict what it prints, then run it and change one value.

Working example
Expected output: done

Why this matters

Promises replaced deeply nested callback pyramids with a flat, chainable, and far more readable way to sequence async work.

Real-world example

Every fetch() call returns a Promise that eventually fulfills with a Response or rejects with a network error.

Common mistakes

  • Forgetting to return a Promise from a .then() callback, breaking the chain
  • Not attaching a .catch() and letting rejections go unhandled
  • Nesting .then() calls instead of chaining them flatly

Try it yourself

Challenge

Write delay(ms, value) returning a Promise that resolves with value after ms.

Practice

Knowledge check

How many times can a single Promise settle?

Summary

A Promise settles exactly once, to fulfilled or rejected; chain with .then() and always handle rejection with .catch().