What is the purpose of Promise.all() in JavaScript?
a) To execute multiple promises in parallel and wait until all are resolved
b) To execute a promise multiple times
c) To create a new promise that resolves to the first settled promise
d) To cancel all promises
Answer:
a) To execute multiple promises in parallel and wait until all are resolved
Explanation:
The Promise.all()
method takes an array of promises and returns a single promise that resolves when all of the promises have been resolved. If any promise in the array is rejected, the entire Promise.all()
will reject with that reason.