🟒 EasyAsync BugsπŸ› Debug Challenge

Missing await causes wrong result

Buggy Code β€” Can you spot the issue?

async function getUser(id) {
  const user = fetch(`/api/users/${id}`)
    .then(r => r.json());
  console.log(user);
  return user;
}

Fixed Code

async function getUser(id) {
  const user = await fetch(`/api/users/${id}`)
    .then(r => r.json());
  console.log(user);
  return user;
}

Bug Explained

Bug: fetch() returns a Promise. Without await, user is a Promise object, not the resolved data.

Explanation: Without await, user holds the Promise itself. Adding await pauses execution until the Promise resolves and gives you the actual data.

Key Insight: Always await async operations inside async functions. A missing await is one of the most common async bugs.

More Async Bugs Debug Challenges

🟑 MediumSequential awaits killing performanceβ†’πŸŸ‘ MediumSwallowed error in async functionβ†’πŸ”΄ HardAsync function in forEachβ†’πŸ”΄ HardRace condition in state updateβ†’

Practice spotting bugs live β†’

38 debug challenges with AI hints

πŸ› Try Debug Lab