Find the Fetch Mistake
Find the Mistake Medium
Question
This function does not return the data correctly. Find and fix the mistake.
Code
async function getUser(id) {
const res = await fetch("/api/users/" + id);
const data = res.json();
return data;
}
Hint
res.json() returns a Promise — it needs to be awaited.
Explanation
res.json() returns a Promise, not the parsed data directly. Without 'await', data is a pending Promise, not the actual JSON. The fix is: const data = await res.json();. The same applies to res.text() and res.blob().
Related Resources
Related Lessons
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.