Asynchronous Programming13% of the exam

Promises, async and await

How a promise settles once, how values and errors travel through then, catch and finally, which of Promise.all, allSettled, race and any fits a requirement, how to wrap a callback API in a promise, and how async functions and await behave, including sequential versus parallel awaits, missing await or return bugs, and top-level await.

Official exam objective
Given a scenario, apply asynchronous programming concepts.

~7 min read · 21 practice questions ·

What the exam expects

  • Predict what a promise chain logs: settle-once, values returned (or not) from then, errors skipping to catch, recovery after catch, and the transparent finally.
  • Pick Promise.all, allSettled, race or any from a requirement, and predict result order and failure behavior.
  • Wrap a callback API in new Promise and flatten nested callbacks with async/await.
  • Use async functions correctly: they always return a promise, await runs steps sequentially unless you start them first, and a missing await or return loses ordering and errors.
  • Key terms: pending / fulfilled / rejected (a promise's states; settled means not pending); executor (the function passed to new Promise that calls resolve or reject); chain (each then returns a new promise); floating promise (one started but neither returned nor awaited); top-level await (await outside any function, valid only in modules).

Key facts

Settle once
Detail
Only the first resolve/reject call counts
then callback return
Detail
Becomes the next promise's value; none means undefined
finally callback
Detail
No argument; return value ignored unless it throws or rejects
Promise.all
Detail
Input-order array; rejects on first rejection
Promise.allSettled
Detail
Never rejects; {status, value/reason} per input
Promise.race
Detail
Mirrors the first input to settle
Empty input array
Detail
all fulfills with []; any rejects with AggregateError; race stays pending forever
Promise.any all rejected
Detail
AggregateError; errors in input order
Async function result
Detail
Always a promise; uncaught throw rejects it
Top-level await
Detail
Only in modules; elsewhere a SyntaxError
forEach with async callback
Detail
Does not wait for the promises
Response body
Detail
Readable once; clone() before reading to reuse
Sources for this section (11)
  • Why does `100 - getDiscount()` log `NaN` when `getDiscount` is an async function returning 10?
  • When should you choose `Promise.race` over `Promise.any`?
  • Why does a chain continue normally after a `catch` that returns a value?
  • In what order does `Promise.all` return results from inputs that finish at different times?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the JavaScript Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 24 lessons of the JavaScript Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (21 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the JavaScript Developer exam