# Promises, async and await

*JavaScript Developer Study Guide · Asynchronous Programming · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/asynchronous-programming/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.

- Certification: Salesforce JavaScript Developer
- Exam section: Asynchronous Programming
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a scenario, apply asynchronous programming concepts.

## 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

| Fact | Detail | Source |
|---|---|---|
| Settle once | Only the first `resolve`/`reject` call counts | [Promise() constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) |
| `then` callback return | Becomes the next promise's value; none means `undefined` | [then()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) |
| `finally` callback | No argument; return value ignored unless it throws or rejects | [finally()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) |
| `Promise.all` | Input-order array; rejects on first rejection | [Promise.all()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) |
| `Promise.allSettled` | Never rejects; `{status, value/reason}` per input | [Promise.allSettled()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) |
| `Promise.race` | Mirrors the first input to settle | [Promise.race()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race) |
| Empty input array | `all` fulfills with `[]`; `any` rejects with `AggregateError`; `race` stays pending forever | [Promise.all()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), [Promise.any()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any), [Promise.race()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race) |
| `Promise.any` all rejected | `AggregateError`; `errors` in input order | [Promise.any()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any) |
| Async function result | Always a promise; uncaught throw rejects it | [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) |
| Top-level `await` | Only in modules; elsewhere a `SyntaxError` | [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await) |
| `forEach` with async callback | Does not wait for the promises | [forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) |
| Response body | Readable once; `clone()` before reading to reuse | [Using the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) |

## Check yourself

- 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?

## Sources

- [Using promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)
- [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
- [Introducing asynchronous JavaScript](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Async_JS/Introducing)
- [Promise() constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise)
- [Promise.prototype.then()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
- [Promise.prototype.finally()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
- [Promise.all()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
- [Promise.allSettled()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
- [Promise.race()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
- [Promise.any()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
- [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
- [Array.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
- [Using the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 21 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
