Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What does Promise.all() do when provided with multiple promises?

View

What is the behavior of Promise.race()?

View

What is the difference between Promise.all() and Promise.allSettled()?

View

How can you handle multiple promises in parallel but ensure that they all complete, even if some fail?

View

What happens if one of the promises in Promise.all() rejects?

View

How can you ensure that the fastest resolving promise is returned, regardless of whether it resolves or rejects?

View

What does Promise.any() do?

View

What will happen if none of the promises resolve in Promise.any()?

View

How can you cancel or abort a promise in JavaScript?

View

How does Promise.finally() work in promise chains?

View

What does Promise.all() do when provided with multiple promises?

It waits for all promises to either resolve or reject and returns a single promise that resolves to an array of results.
It resolves the first promise in the array and ignores the rest.
It rejects if any of the promises take too long to resolve.
It only waits for the first promise to resolve before continuing.

What is the behavior of Promise.race()?

It resolves only if all promises are resolved.
It resolves or rejects as soon as the first promise in the array settles (either resolves or rejects).
It waits for the slowest promise to resolve.
It rejects if any promise is rejected.

What is the difference between Promise.all() and Promise.allSettled()?

Promise.all() fails if any promise is rejected, while Promise.allSettled() returns the outcome of all promises, whether they resolve or reject.
Promise.all() waits for the fastest promise, while Promise.allSettled() waits for all promises.
Promise.allSettled() is faster than Promise.all().
There is no difference between the two.

How can you handle multiple promises in parallel but ensure that they all complete, even if some fail?

Use Promise.allSettled() to get the results of all promises, regardless of whether they resolve or reject.
Use Promise.all() and catch individual errors.
Use Promise.race() for faster promise resolution.
Use a for loop to await each promise sequentially.

What happens if one of the promises in Promise.all() rejects?

The rejected promise is ignored, and the rest continue.
All promises are executed in parallel, even if one rejects.
The entire Promise.all() rejects, and the other promises are ignored.
Promise.all() still resolves with partial results.

How can you ensure that the fastest resolving promise is returned, regardless of whether it resolves or rejects?

Use Promise.all() to return the fastest resolved promise.
Use Promise.race() to return the first settled promise.
Use Promise.allSettled() for the fastest result.
Use Promise.any() to get the fastest resolved promise.

What does Promise.any() do?

It returns the first resolved promise, ignoring rejected promises, and only fails if all promises reject.
It returns the first promise that resolves or rejects.
It waits for all promises to resolve and rejects if any promise fails.
It waits for the slowest promise to resolve.

What will happen if none of the promises resolve in Promise.any()?

It waits indefinitely for a resolved promise.
It ignores the rejected promises and resolves with undefined.
It throws an aggregate error if all promises reject.
It automatically resolves to the first promise in the array.

How can you cancel or abort a promise in JavaScript?

Promises in JavaScript cannot be canceled directly, but you can use techniques like AbortController to manage long-running async tasks.
Use Promise.race() to cancel a slower promise.
Use Promise.reject() to cancel a promise.
Use Promise.all() with a cancellation token.

How does Promise.finally() work in promise chains?

It executes a callback after the promise is settled, whether it resolves or rejects.
It only executes if the promise resolves.
It catches errors in the promise chain.
It cancels the promise if it takes too long.