JavaScriptInterview preparation
Intermediate·Concept·2 min read

Which Promise method should I use?

Practice this question

Definition:

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.

Key points:

  • 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

Interview point:

  • State what happens on failure as well as on success, and mention concurrency limits for large input lists.
Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “Which Promise method should I use?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.