0
0
Javascriptprogramming~5 mins

Await keyword behavior in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOnly inside callback functions
BInside async functions or top-level modules with top-level await
COnly inside regular functions
DAnywhere in the code
What does await do when given a non-Promise value?
AThrows an error
BWaits indefinitely
CReturns the value immediately as if it was a resolved Promise
DConverts it to a rejected Promise
What happens to the rest of the program when an async function hits await?
AOnly the async function pauses; other code continues running
BThe whole program stops
CThe browser reloads
DThe event loop freezes
Which of these is a key difference between await and .then()?
A<code>await</code> pauses execution; <code>.then()</code> does not
B<code>.then()</code> pauses execution; <code>await</code> does not
CBoth pause execution
DNeither pause execution
If a Promise rejects, what happens when you use await on it?
AThe rejection is ignored
BThe Promise resolves instead
CThe program crashes immediately
DThe async function throws an error at the <code>await</code> line
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.