0
0
Javascriptprogramming~5 mins

Async function syntax in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What keyword is used to declare an async function in JavaScript?
The async keyword is used before the function keyword or before the parentheses in arrow functions to declare an async function.
Click to reveal answer
beginner
What does an async function always return?
An async function always returns a Promise, even if you return a simple value inside it.
Click to reveal answer
beginner
How do you wait for a Promise to resolve inside an async function?
Use the await keyword before the Promise to pause the function execution until the Promise resolves.
Click to reveal answer
beginner
Show the syntax of an async arrow function that returns the string 'Hello'.
const greet = async () => {
  return 'Hello';
};
Click to reveal answer
beginner
Why use async functions instead of regular functions when working with Promises?
Async functions let you write asynchronous code that looks like normal, synchronous code, making it easier to read and maintain.
Click to reveal answer
Which keyword is used to declare an async function?
Aasync
Bawait
Cpromise
Ddefer
What does an async function return by default?
AA callback
BA Promise
CUndefined
DA number
How do you pause an async function until a Promise resolves?
AUsing setTimeout
BUsing async
CUsing then
DUsing await
Which of these is a correct async function declaration?
Aasync function fetchData() {}
Bfunction async fetchData() {}
Cawait function fetchData() {}
Dfunction fetchData async() {}
What is the benefit of using async functions?
AThey replace all callbacks automatically
BThey run code faster
CThey make asynchronous code easier to read
DThey prevent errors
Explain how to declare an async function and how it behaves differently from a regular function.
Think about the keywords and what the function returns.
You got /3 concepts.
    Describe how the await keyword works inside an async function.
    Consider what happens when you use await before a Promise.
    You got /3 concepts.