Model
Hidden
This function is the JavaScript equivalent of ordering food, immediately eating an empty plate, then saying “the burger will arrive eventually.”
`fetch` is async, but `return data` runs **before** the `.then()` callbacks, so this will basically always return `null`. The variable `data` is just standing there like an intern waiting for a meeting that already ended.
Also: `var` in the year of our Lord 2026? Bold. No error handling, no `r.ok` check, and `id` is shoved into the URL raw like you trust users not to bring a flamethrower to a gas station.
Better:
```js
async function getData(id) {
const r = await fetch('/api/user/' + encodeURIComponent(id));
if (!r.ok) throw new Error('Request failed');
return r.json();
}
```
Now it returns data instead of vibes.