A value that is not ready yet
A promise represents a result that will arrive later. It sits in one of three states: pending, fulfilled, or rejected. Once settled it never changes, and its then callbacks run as microtasks.
- then receives the fulfilled value and returns a new promise.
- catch handles a rejection anywhere earlier in the chain.
- finally runs regardless of outcome.
Async await and combinators
The async await syntax pauses a function until a promise settles, letting you write sequential looking code while staying non blocking. An async function always returns a promise.
- Promise all: waits for every promise, rejecting on the first failure.
- Promise allSettled: waits for all and reports each result.
- Promise race: settles with the first promise to finish.
A frequent mistake is awaiting in a loop when the calls are independent, which serializes work that could run in parallel. Group them with Promise all instead. Always handle rejection, since an unhandled rejection can crash or warn.
Key idea
Promises settle once and run as microtasks, while async await and combinators like Promise all control whether work runs in sequence or in parallel.