Recall & Review
beginner
What does the
await keyword do in JavaScript?It pauses the execution of an async function until the Promise after
await settles (resolves or rejects), then resumes with the resolved value or throws the rejection.Click to reveal answer
beginner
Can
await be used outside of an async function?No,
await can only be used inside async functions or in top-level modules that support top-level await.Click to reveal answer
intermediate
What happens if you
await a non-Promise value?The value is converted to a resolved Promise automatically, so
await returns the value immediately without delay.Click to reveal answer
intermediate
How does
await affect the event loop?await pauses the async function but allows other code and events to run in the event loop until the awaited Promise settles.Click to reveal answer
intermediate
What is the difference between
await and .then()?await makes asynchronous code look synchronous and pauses execution, while .then() registers callbacks without pausing execution.Click to reveal answer
Where can you use the
await keyword in JavaScript?✗ Incorrect
await works only inside async functions or in modules that support top-level await.What does
await do when given a non-Promise value?✗ Incorrect
await treats non-Promise values as resolved Promises and returns them immediately.What happens to the rest of the program when an async function hits
await?✗ Incorrect
Only the async function pauses at
await, allowing other code and events to run.Which of these is a key difference between
await and .then()?✗ Incorrect
await pauses the async function, making code look synchronous; .then() uses callbacks without pausing.If a Promise rejects, what happens when you use
await on it?✗ Incorrect
When a Promise rejects,
await throws an error that can be caught with try/catch.Explain how the
await keyword changes the flow of an async function.Think about how <code>await</code> makes asynchronous code easier to read.
You got /4 concepts.
Describe the difference between using
await and .then() for handling Promises.Consider how the code looks and behaves when using each.
You got /4 concepts.