Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


What does the Promise.race method return when multiple promises are passed to it?

  1. "one"

  2. "two"

  3. "two" "one"

  4. "one" "two"

The correct answer is: "two"

The Promise.race method is a part of the JavaScript Promise API that returns a promise which resolves or rejects as soon as one of the promises in the iterable (the array of promises passed to it) resolves or rejects, with the value or reason from that promise. This means that it acts on the first promise that settles, whether it resolves or rejects. In this context, the reference to "one" and "two" suggests that there are at least two promises being raced against each other. If "two" represents the result of the first promise that resolves or rejects, the return value of the Promise.race would then be "two". This occurs because the promise that resolves first will determine the outcome of the race, and its value will be returned. The other choices do not accurately reflect how Promise.race functions, as they might imply that all promises' results are returned or that the order of resolution affects the output, which is not the case. In essence, since Promise.race only cares about the first settled promise, the option indicating "two" as the specific returned value aligns with the behavior of the method.