Challenge - 5 Problems
Async/Await Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of async function with await
What will be the output of this Node.js code snippet?
Node.js
async function fetchData() { return 'data'; } async function main() { const result = await fetchData(); console.log(result); } main();
Attempts:
2 left
💡 Hint
Remember that await unwraps the resolved value of a promise inside an async function.
✗ Incorrect
The async function fetchData returns a resolved promise with 'data'. Await unwraps it, so console.log prints 'data'.
❓ component_behavior
intermediate2:00remaining
Behavior of async function returning a rejected promise
What happens when this async function is called without a try/catch block?
Node.js
async function fail() { throw new Error('fail'); } fail();
Attempts:
2 left
💡 Hint
Async functions always return promises, even when throwing errors.
✗ Incorrect
Throwing inside async returns a rejected promise. Without await or catch, no synchronous error occurs.
📝 Syntax
advanced2:00remaining
Identify the incorrect usage in async/await
Which option contains incorrect usage of async/await?
Node.js
async function test() { const data = await fetchData(); return data; }
Attempts:
2 left
💡 Hint
Remember that await expects a function call returning a promise, not the function itself.
✗ Incorrect
Option A misses parentheses after fetchData, so await is applied to the function object instead of calling it.
🔧 Debug
advanced2:00remaining
Why does this async function never resolve?
Consider this code. Why does the console.log never run?
Node.js
async function waitForever() { await new Promise(() => {}); console.log('Done'); } waitForever();
Attempts:
2 left
💡 Hint
What happens if a promise never settles?
✗ Incorrect
The promise passed to await never calls resolve or reject, so await waits forever and console.log never runs.
🧠 Conceptual
expert2:00remaining
Effect of missing await in async function call
What is the value of variable result after running this code?
Node.js
async function getValue() { return 42; } const result = getValue();
Attempts:
2 left
💡 Hint
Async functions always return promises, even if you don't use await.
✗ Incorrect
Calling an async function returns a promise immediately. Without await, result is that promise, not the resolved value.