Skip to content

Chapter 21 of 33

Promises

Compose fulfillment, rejection, cleanup, and concurrent aggregation without nesting.

42 minutes 10 quick checksBy Subha Prasad
Lesson 21 of 33Course navigation

Lesson content

Read, practise, then check your understanding

A Promise is pending then permanently fulfilled or rejected. then returns a new Promise and adopts returned values/Promises; thrown errors become rejections.

Composition

fetchProfile(id)
  .then(profile => fetchPermissions(profile.id))
  .then(render)
  .catch(reportError)
  .finally(hideSpinner);

Return nested Promises so chains remain flat. Promise.all is fail-fast, allSettled reports every outcome, race settles first, and any fulfills first. Promise construction executes synchronously; reactions run as microtasks. A Promise alone does not cancel underlying work—pair APIs with AbortSignal or another explicit cancellation contract.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes Promise?
Which JavaScript term matches this description: An object representing eventual fulfillment or rejection.
Which statement best describes then?
Which JavaScript term matches this description: Registration of fulfillment and optional rejection transformations.
Which statement best describes catch?
Which JavaScript term matches this description: Promise-chain registration of rejection handling.
Which statement best describes finally?
Which JavaScript term matches this description: Promise-chain follow-up that does not receive the settled value.
Which statement best describes Promise.all?
Which JavaScript term matches this description: Fail-fast aggregation that fulfills with ordered results when every input fulfills.

0 of 10 checks passed

Your progress is saved on this device.