Understanding Promise.all
What does the method Promise.all return if passed an array of multiple pending promises?
- A single promise that resolves when all input promises resolve
- A single promise that rejects immediately
- Each promise in an array
- The value of the fastest promise
- A function to cancel all promises
Behavior of Promise.race
Given Promise.race([p1, p2]), what does the resulting promise resolve or reject with?
- The outcome of the first settled promise in the array
- The result of the last promise
- The sum of all resolved values
- An array of all promises
- An error if any promise fails
Purpose of Promise.allSettled
If you use Promise.allSettled with promises that both resolve and reject, what is returned?
- An array of objects that each describe the outcome of every promise
- A rejected promise overall
- The resolved value of the first successful promise
- A string indicating success or failure
- Nothing is returned
Promise.any Method
What does Promise.any([p1, p2, p3]) resolve with if p2 resolves first?
- The value that p2 resolves with
- The value that the last promise resolves with
- The value from the fastest rejected promise
- An array of all resolved values
- It always rejects
Settling Behavior in Promise.all
If one of the promises passed to Promise.all rejects, what happens?
- Promise.all immediately rejects with that error
- Promise.all waits for all promises then resolves
- It continues with remaining promises
- It skips the rejected promise
- Returns undefined
Order of Results in Promise.all
If you pass [p1, p2, p3] to Promise.all, what is the order of resolution values in the result?
- The order matches the original promise array
- Random order depending on which resolves first
- Sorted by resolved values
- Reverse order from the array
- Only the first resolved value
Promise.resolve Utility
Which statement accurately describes Promise.resolve(5)?
- It returns a promise that immediately resolves with 5
- It returns a promise that never settles
- It throws an error with value 5
- It rejects the promise with value 5
- It returns 5
Promise.reject Behavior
What does Promise.reject('fail') return?
- A promise that immediately rejects with 'fail'
- A resolved value of 'fail'
- A function that throws 'fail' later
- Nothing is returned
- A string 'fail'
Promise.allSettled Edge Case
If Promise.allSettled receives an empty array, what does it return?
- A promise resolved with an empty array
- A rejected promise
- null
- A pending promise forever
- An error is thrown
Difference between Promise.all and Promise.race
How does Promise.race differ from Promise.all when given multiple promises?
- Promise.race settles as soon as the first promise settles, while Promise.all waits for all
- Promise.all rejects for any promise, while Promise.race only resolves
- Promise.race only accepts resolved promises
- Promise.all returns a single value but Promise.race returns an array
- Promise.race is slower than Promise.all