Skip to main content
JavaScript Output Prediction Hard +35 XP

Promise.race

What gets logged?

JavaScriptRead-only
const p1 = new Promise(r => setTimeout(() => r("slow"), 200));
const p2 = new Promise(r => setTimeout(() => r("fast"), 100));
Promise.race([p1, p2]).then(console.log);

What is the output?

Show answer and explanation

Answer: fast

Promise.race resolves with the first promise to settle. p2 resolves after 100ms, before p1's 200ms.

Hint: race = first one wins.

What this challenge tests

Output Prediction in JavaScript: promises, race.

Related challenges