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 can you ensure that even if one promise fails, other promises are awaited using async/await?

View

What is a key difference between Promise.all() and Promise.allSettled() when using async/await?

View

How can you handle errors in multiple promises when using await?

View

What does the finally block do when used in conjunction with async/await?

View

What will the following code output?

View

What happens if you use await with a promise that never resolves or rejects?

View

Can you use await in a loop to handle promises sequentially?

View

What will happen if await is used with a synchronous function?

View

What does await Promise.all([promise1, promise2]) do?

View

How can you handle multiple promises sequentially using async/await?

View

How can you ensure that even if one promise fails, other promises are awaited using async/await?

Use Promise.allSettled() instead of Promise.all().
Use try...catch for each promise.
Use a for loop with await.
Use Promise.race() to handle rejections.

What is a key difference between Promise.all() and Promise.allSettled() when using async/await?

Promise.allSettled() waits for all promises to either resolve or reject without failing immediately.
Promise.allSettled() only waits for the first promise to resolve or reject.
Promise.all() handles all promises synchronously.
Promise.all() allows promises to resolve, even if one is rejected.

How can you handle errors in multiple promises when using await?

Use try...catch inside a for loop for each awaited promise.
Use Promise.race() to catch the first error.
Errors cannot be handled with async/await.
Only handle errors after all promises resolve.

What does the finally block do when used in conjunction with async/await?

It runs code after the try or catch block, regardless of the outcome.
It executes only if the promise is resolved.
It runs if an error is thrown in the await statement.
It stops further execution of asynchronous code.

What will the following code output?

async function test() { try { await Promise.reject("Error"); } catch (e) { console.log(e); } finally { console.log("Finally"); } } test();

"Error" followed by "Finally"
"Finally" followed by "Error"
Only "Error"
Only "Finally"

What happens if you use await with a promise that never resolves or rejects?

The async function will wait indefinitely and never continue.
The function will throw an error.
The promise will eventually be rejected.
The async function will move on to the next line.

Can you use await in a loop to handle promises sequentially?

Yes, await pauses execution, so promises will resolve one after another.
No, await always resolves promises in parallel.
Yes, but only if Promise.all() is used.
No, because await cannot be used in loops.

What will happen if await is used with a synchronous function?

The function will execute as if await was not used.
The function will throw an error.
The function will convert to an asynchronous function.
The await keyword will be ignored.

What does await Promise.all([promise1, promise2]) do?

It waits for both promise1 and promise2 to resolve before continuing.
It runs the promises synchronously.
It rejects if either of the promises takes too long.
It waits for the first promise to resolve and ignores the second one.

How can you handle multiple promises sequentially using async/await?

Use a for loop with await.
Use Promise.all() and await.
Use Promise.race() with await.
Use nested then() and catch() statements.