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

How are errors typically handled in callback-based functions?

View

Which method is commonly used to handle errors in promises?

View

How does error handling work in async/await?

View

What happens if a promise is rejected but no .catch() is used to handle it?

View

How can you handle multiple errors when working with Promise.all()?

View

What is the behavior of finally in try...catch...finally blocks?

View

Which of the following can handle errors in both promises and async/await?

View

How do you re-throw an error in a catch block for further handling?

View

What is the output of the following code if an error occurs in someAsyncFunction()?

View

What will happen if no error is thrown in the try block but the finally block has an error?

View

How are errors typically handled in callback-based functions?

By passing an error as the first argument to the callback function.
By using catch blocks in the callback function.
By returning an error object.
By resolving the error in the promise chain.

Which method is commonly used to handle errors in promises?

Using a finally block.
By returning an error from the promise.
Using .catch() to handle the rejected promise
Using throw inside .then().

How does error handling work in async/await?

Errors are ignored automatically.
Errors can be caught using a try...catch block.
Errors must be handled by chaining .catch().
Errors cannot be caught in async functions.

What happens if a promise is rejected but no .catch() is used to handle it?

An unhandled promise rejection error is thrown.
The promise will automatically resolve.
The program will continue without throwing an error.
The promise will be ignored.

How can you handle multiple errors when working with Promise.all()?

Use .then() to handle all errors.
Use Promise.allSettled() to get the status of all promises, whether they resolve or reject.
Use only the first rejected promise.
It is not possible to handle multiple errors.

What is the behavior of finally in try...catch...finally blocks?

finally executes after both try and catch blocks, regardless of whether an error occurred or not.
finally only executes if no error occurred.
finally is only executed if the promise resolves.
finally only handles rejected promises.

Which of the following can handle errors in both promises and async/await?

A try...catch block.
Only .catch() for promises.
throw keyword.
The resolve() function.

How do you re-throw an error in a catch block for further handling?

try { await someAsyncFunction(); } catch (error) { // Re-throw the error }

Use the throw keyword inside the catch block.
Use resolve() to pass the error forward.
Use reject() to propagate the error.
Call the finally block with the error.

What is the output of the following code if an error occurs in someAsyncFunction()?

async function test() { try { await someAsyncFunction(); } catch (error) { throw error; } finally { console.log("Cleaning up"); } } test();

It logs "Cleaning up" and re-throws the error.
It only logs the error.
It ignores the error and logs "Cleaning up."
It catches the error but doesn't log anything.

What will happen if no error is thrown in the try block but the finally block has an error?

The error from the finally block will be thrown.
The code will ignore the error.
The program will execute successfully.
The catch block will handle the error.