1 / 23
Other keys: show •
Space: good •
1-4: rate •
0: skip •
5: flag •
6: invert
Question
What does the async keyword do when placed before a function?
Answer
The async keyword marks a function as asynchronous, so it always returns a Promise and can use await inside.
The function can use await inside to pause execution until a Promise resolves. Even if you return a plain value, it gets wrapped in a resolved Promise automatically.
async function getData() {
// Returns Promise.resolve("hello")
return "hello";
}
Go deeper:
MDN: async function — why the return value is always wrapped in a Promise and how
awaitworks inside.
or press any other key
Note saved — thanks!