Predict async/await Output
Predict Output Medium
Question
What does this code print?
Code
async function fetchData() {
const data = await Promise.resolve(42);
return data * 2;
}
fetchData().then(result => console.log(result));
Hint
await unwraps the Promise value; the async function returns a Promise.
Explanation
await Promise.resolve(42) pauses until the promise resolves, yielding 42. Then data * 2 = 84 is returned. Since fetchData is async, it returns a Promise that resolves with 84. The .then callback receives 84 and prints it.
Related Resources
Related Lessons
- Async JavaScript
Learn about async/await.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.