JavaScriptHardUtilities

Build an API Request Function

Write an async function that fetches user data from an API by ID, handles errors, and returns null if the user is not found or the request fails.

Starter code

JavaScript
async function fetchUser(id) {
  // Your code here
}

// Test (mock)
// fetchUser(1) should return { id: 1, name: 'Alice' }
// fetchUser(999) should return null

Stuck on this challenge?

Let CodeForge AI help you find the solution.