0
0
Node.jsframework~5 mins

Promise.race and Promise.allSettled in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Promise.race do in JavaScript?

Promise.race returns a new promise that settles as soon as any of the input promises settles (either resolves or rejects). It "races" all promises and settles with the first one that finishes.

Click to reveal answer
intermediate
What is the difference between Promise.allSettled and Promise.all?

Promise.allSettled waits for all promises to settle (resolve or reject) and returns their results regardless of success or failure. Promise.all waits for all to resolve but rejects immediately if any promise rejects.

Click to reveal answer
beginner
What does the result of Promise.allSettled look like?

It returns an array of objects, each with a status property ("fulfilled" or "rejected") and either a value (for fulfilled) or reason (for rejected).

Click to reveal answer
beginner
If you want to get the first promise that finishes regardless of success or failure, which method do you use?

You use Promise.race because it settles as soon as any promise settles, whether it resolves or rejects.

Click to reveal answer
beginner
Can Promise.allSettled be used to handle multiple promises without stopping on errors?

Yes, Promise.allSettled lets you wait for all promises to finish and see which succeeded or failed without stopping early due to errors.

Click to reveal answer
What does Promise.race return?
AThe last promise to resolve
BAn array of all resolved values
CAn array of all rejected reasons
DThe result of the first promise to settle (resolve or reject)
Which method waits for all promises to finish regardless of success or failure?
APromise.race
BPromise.allSettled
CPromise.all
DPromise.any
What happens if one promise rejects in Promise.all?
AIt immediately rejects with that error
BIt ignores the rejection
CIt waits for all promises anyway
DIt returns an array of results
What property indicates a promise was fulfilled in Promise.allSettled results?
Astatus: 'rejected'
Breason: 'fulfilled'
Cstatus: 'fulfilled'
Dvalue: 'fulfilled'
Which method would you use to get the fastest successful promise result, ignoring failures?
APromise.any
BPromise.allSettled
CPromise.race
DPromise.all
Explain how Promise.race works and give a simple example.
Think about a race where the first to finish wins.
You got /3 concepts.
    Describe the purpose of Promise.allSettled and how its results are structured.
    It tells you how every promise ended, no matter what.
    You got /4 concepts.