Challenge - 5 Problems
Promise.all Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Promise.all example?
Consider the following Node.js code using Promise.all. What will be logged to the console?
Node.js
const p1 = Promise.resolve(10); const p2 = new Promise(resolve => setTimeout(() => resolve(20), 100)); const p3 = Promise.resolve(30); Promise.all([p1, p2, p3]).then(results => console.log(results));
Attempts:
2 left
💡 Hint
Promise.all waits for all promises to resolve and keeps the order of the input array.
✗ Incorrect
Promise.all returns an array of results in the same order as the promises were passed, regardless of which resolves first.
📝 Syntax
intermediate2:00remaining
Which option correctly uses Promise.all to fetch data?
You want to fetch data from three URLs in parallel using Promise.all. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Promise.all expects a single array of promises.
✗ Incorrect
Promise.all requires an array of promises. Option B correctly awaits the array of fetch promises.
🔧 Debug
advanced2:00remaining
Why does this Promise.all code never resolve?
Look at this code snippet. Why does the Promise.all never resolve or reject?
Node.js
const p1 = new Promise(() => {});
const p2 = Promise.resolve(2);
Promise.all([p1, p2]).then(console.log).catch(console.error);Attempts:
2 left
💡 Hint
A promise that never settles blocks Promise.all from finishing.
✗ Incorrect
Promise.all waits for all promises to settle. Since p1 never settles, Promise.all never resolves or rejects.
❓ state_output
advanced2:00remaining
What is the value of 'results' after this Promise.all call?
Given the code below, what will be the value of 'results' inside the then callback?
Node.js
const p1 = Promise.resolve('a'); const p2 = Promise.resolve('b'); const p3 = Promise.resolve('c'); Promise.all([p1, p2, p3]).then(results => { // What is results? console.log(results); });
Attempts:
2 left
💡 Hint
Promise.all preserves the order of promises in the input array.
✗ Incorrect
The results array matches the order of the input promises regardless of resolution timing.
🧠 Conceptual
expert2:00remaining
Which option best describes Promise.all behavior when one promise rejects?
What happens when one promise in Promise.all rejects while others are still pending?
Attempts:
2 left
💡 Hint
Promise.all rejects as soon as any promise rejects.
✗ Incorrect
Promise.all rejects immediately when any promise rejects, with that rejection reason.