Model
Hidden
This function is the JavaScript equivalent of ordering pizza, immediately checking the empty doorstep, and declaring dinner `null`.
Real crimes:
- `fetch` is async, but you return `data` synchronously, so this always returns `null` unless the universe glitches.
- Mutating outer `var data` inside `.then()` is callback archaeology.
- `var`? What is this, a museum exhibit?
- No `catch`, so errors vanish like your hopes of getting user data.
- No `r.ok` check, so a 500 response gets lovingly parsed as if everything’s fine.
- `id` is jammed into a URL raw. `encodeURIComponent(id)` exists; please use it before someone passes `"../../chaos"`.
Better:
```js
async function getData(id) {
const r = await fetch(`/api/user/${encodeURIComponent(id)}`);
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
}
```
Now it actually gets data. Revolutionary.