Recall & Review
beginner
What does the
async keyword do when placed before a function?It makes the function return a Promise automatically and allows the use of
await inside it to pause execution until a Promise resolves.Click to reveal answer
beginner
How does the
await keyword work inside an async function?It pauses the function execution until the awaited Promise settles, then returns the resolved value or throws an error if rejected.
Click to reveal answer
intermediate
Why should you use
try/catch blocks with async/await?Because
await can throw errors if the Promise rejects, so try/catch helps handle those errors gracefully.Click to reveal answer
intermediate
What happens if you use
await outside of an async function?It causes a syntax error because
await can only be used inside functions declared with async or in top-level modules supporting top-level await.Click to reveal answer
advanced
How can you run multiple asynchronous operations in parallel using
async/await?Start all Promises without awaiting them immediately, then use
await Promise.all([...]) to wait for all to finish together.Click to reveal answer
What does the
async keyword do to a function?✗ Incorrect
The
async keyword makes the function return a Promise, enabling the use of await inside.Where can you use the
await keyword?✗ Incorrect
await can only be used inside async functions or in modules that support top-level await.What is the best way to handle errors when using
await?✗ Incorrect
Using
try/catch blocks lets you catch and handle errors from rejected Promises when using await.How do you run multiple async tasks in parallel with
async/await?✗ Incorrect
Starting all Promises first and then awaiting
Promise.all runs them in parallel efficiently.What happens if an awaited Promise rejects and you don't catch the error?
✗ Incorrect
If you don't catch errors from rejected Promises, they remain unhandled and can crash your program.
Explain how
async and await work together to handle asynchronous code in Node.js.Think about how you wait for a friend to arrive before starting an activity.
You got /4 concepts.
Describe how to handle errors when using
await in your code.Imagine catching a ball so it doesn't fall and break.
You got /3 concepts.