LESSON 14 / 16·2 min readIntermediate

Working with promises

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

Promise combinators combine several promises into one result. The correct method depends on whether you need every success, every outcome, the first outcome or the first success. They observe promises; they do not automatically cancel ongoing operations when the combined result settles.

Important ideas

  • all: need every result; rejects when one rejects, but does not cancel the others.

  • allSettled: need the result of every task, including failures.

  • race: first settled result. any: first success, or rejection if all fail.

  • Promise.all keeps results in input order, even if the operations finish in a different order.

  • Promise.any rejects with an AggregateError if every input rejects.

  • A timeout implemented with race only stops waiting; cancel the underlying operation separately when supported.

Comparison:

MethodSuccessful resultFailure behavior
allAll fulfilled values in input orderRejects on an input rejection
allSettledStatus/result for every inputInput rejection becomes a result item
raceFirst settled input's outcomeRejects if first settled input rejects
anyFirst fulfilled valueRejects if all inputs reject
PAUSE & RECALL

Can you explain it without the notes?

Which Promise method should I use?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Promise combinators combine several promises into one result. The correct method depends on whether you need every success, every outcome, the first outcome or the first success. They observe promises; they do not automatically cancel ongoing operations when the combined result settles.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • State what happens on failure as well as on success, and mention concurrency limits for large input lists.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Why does forEach with async cause problems?

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “Which Promise method should I use?”. Examples are study fragments; framework behavior can depend on your version.