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 do you convert a callback-based function into a promise-based one?

View

How does util.promisify() help in Node.js?

View

What is the main benefit of using async/await over callbacks?

View

How do you handle errors in an async/await function when calling a callback-based function?

View

What is the output of the following code?

View

Which of the following is true about combining async/await and promises?

View

How do you handle a promise rejection inside an async function?

View

What is the output of the following code?

View

What is the main reason for using promises instead of traditional callbacks?

View

How can you combine multiple asynchronous operations using both promises and async/await?

View

How do you convert a callback-based function into a promise-based one?

Use the Promise constructor to wrap the callback and resolve/reject based on the callback's outcome.
Replace the callback with an async function.
Use await inside the callback.
Call the callback inside a .then() method.

How does util.promisify() help in Node.js?

It converts callback-based functions into promise-based functions.
It automatically chains promises.
It converts synchronous functions into asynchronous ones.
It resolves promises faster.

What is the main benefit of using async/await over callbacks?

It makes callbacks run faster.
It automatically handles errors.
It simplifies the readability and maintenance of asynchronous code.
It eliminates the need for promises.

How do you handle errors in an async/await function when calling a callback-based function?

Call the callback inside a .catch() method.
Use .then() and .catch() inside the async function.
Use a try...catch block to catch errors when using await.
Errors are automatically handled in async functions.

What is the output of the following code?

async function fetchData() { return "Data fetched"; } fetchData().then((result) => console.log(result));

undefined
"Data fetched"
An error is thrown.
The function does not return anything.

Which of the following is true about combining async/await and promises?

Promises must be converted into callbacks to work with async/await.
You can use await to pause the execution of an async function until a promise resolves.
await can only be used with Promise.allSettled().
Promises are ignored when using async/await.

How do you handle a promise rejection inside an async function?

Use a try...catch block to handle rejections.
Use .then() to handle the rejection.
Rejections cannot occur inside async functions.
Rejections are automatically handled inside async functions.

What is the output of the following code?

async function getResult() { try { const result = await Promise.reject("Failure"); } catch (error) { console.log(error); } } getResult();

"Failure"
The function will resolve with undefined.
An error is thrown.
The promise will remain pending.

What is the main reason for using promises instead of traditional callbacks?

Promises provide better error handling and readability than callbacks, helping to avoid "callback hell."
Promises run faster than callbacks.
Promises allow synchronous code execution.
Promises do not require async/await.

How can you combine multiple asynchronous operations using both promises and async/await?

Use Promise.all() with await to handle multiple asynchronous operations.
Use multiple async functions inside one await statement.
You cannot combine promises with async/await.
Use .then() and .catch() instead of async/await.