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 happens when you return a value from the .then() method in a promise chain?

View

How do you ensure that promises run sequentially rather than in parallel?

View

What is the purpose of Promise.allSettled()?

View

How can you prevent an unhandled promise rejection?

View

What is the output of the following code?

View

What happens if you omit a .catch() block in a promise chain where an error occurs?

View

What is the advantage of using Promise.all()?

View

How can you handle errors in a promise chain that involves multiple .then() calls?

View

What will happen if you return a rejected promise from within a .then() method?

View

What is the result of Promise.race()?

View

What happens when you return a value from the .then() method in a promise chain?

The returned value is wrapped in a resolved promise.
The returned value is ignored.
The chain will break, and the next .then() will not be called.
It will reject the promise with the returned value.

How do you ensure that promises run sequentially rather than in parallel?

Chain promises using .then() or async/await to execute them one after the other.
Use Promise.all() to execute them sequentially.
Use Promise.race() to handle sequential execution.
Promises always run sequentially by default.

What is the purpose of Promise.allSettled()?

It waits for all promises to either resolve or reject and returns an array of the results, regardless of whether they resolved or rejected.
It returns the first promise to resolve.
It only handles resolved promises.
It cancels all promises if one fails.

How can you prevent an unhandled promise rejection?

Use await instead of .then().
Always use .catch() at the end of the promise chain.
Use Promise.all() to handle rejections.
Avoid creating promises that might reject.

What is the output of the following code?

Promise.resolve(1) .then((result) => { return result + 1; }) .then((result) => { throw new Error("Error"); }) .catch((error) => { console.log(error.message); });

The promise will resolve successfully with no output.
"Error"
"1"
Unhandled promise rejection.

What happens if you omit a .catch() block in a promise chain where an error occurs?

The promise will result in an unhandled rejection, potentially leading to runtime errors.
The promise chain will ignore the error.
The promise will still resolve.
The error is automatically logged.

What is the advantage of using Promise.all()?

It ensures that promises run sequentially.
It allows you to run multiple promises in parallel and get results once all promises have resolved.
It guarantees the fastest promise will resolve first.
It prevents promises from rejecting.

How can you handle errors in a promise chain that involves multiple .then() calls?

Use a single .catch() at the end of the chain to handle any errors that occur.
Use a try...catch block in each .then() call.
Add .catch() after every .then() call.
Promises do not allow error handling.

What will happen if you return a rejected promise from within a .then() method?

The promise chain will break, and no further .then() calls will be made.
It will throw an error and stop execution.
The next .catch() in the chain will handle the rejection.
It will resolve the promise with the rejection value.

What is the result of Promise.race()?

It returns the result of the first promise that resolves or rejects.
It waits for all promises to resolve.
It resolves only if all promises are successful.
It cancels the slower promises.