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 the following code output?

View

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

View

Can you use await outside of async functions in JavaScript?

View

What happens if you forget to use await in front of a promise inside an async function?

View

How do you return multiple resolved promises in parallel using async/await?

View

What is the purpose of Promise.all() in combination with async/await?

View

What will the following code output?

View

What will happen if an await statement is used on a non-promise value?

View

What will happen if you await a rejected promise without handling the rejection?

View

Which of the following is an incorrect way to use await with an asynchronous function?

View

What does the following code output?

async function test() { return "Hello"; } test().then(console.log);

"Hello"
A promise object.
undefined
An error.

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

Wrap the await statement in a try...catch block.
Use .then() and .catch() chaining.
Handle it inside the finally block.
Use a callback.

Can you use await outside of async functions in JavaScript?

No, await can only be used inside async functions
Yes, it will work with regular functions.
Yes, but only with callbacks.
Yes, but only in Node.js.

What happens if you forget to use await in front of a promise inside an async function?

The promise will be executed, but the function will return before the promise resolves.
The function will wait for the promise.
The code will throw an error.
The promise will be automatically awaited.

How do you return multiple resolved promises in parallel using async/await?

Use Promise.all() with await.
Use multiple await statements in a row.
Return promises using setTimeout().
Use await inside a loop.

What is the purpose of Promise.all() in combination with async/await?

It waits for all promises to resolve or reject before proceeding.
It executes promises one by one.
It makes promises run synchronously.
It cancels all unresolved promises.

What will the following code output?

async function test() { let result = await Promise.resolve("Success"); console.log(result); } test();

"Success"
undefined
A rejected promise.
Nothing, as the promise was not awaited.

What will happen if an await statement is used on a non-promise value?

The value is automatically wrapped in a resolved promise.
An error will be thrown.
The code will break at runtime.
The value is ignored.

What will happen if you await a rejected promise without handling the rejection?

The program will throw an unhandled rejection error.
The code will run without issue.
The promise will resolve automatically.
The error will be ignored.

Which of the following is an incorrect way to use await with an asynchronous function?

Using await outside of an async function.
Using await inside an async function.
Using await with Promise.all().
Using await with a resolved promise.