$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #29

Which fix removes the bug?

async function getData() {
  const res = fetch("/api");
  return res.json();
}
  1. Remove async from the function
  2. Change res.json() to res.json
  3. Add await before fetch("/api")
  4. Wrap the body in try/catch
fetch returns a promise that must be awaited first.
Play Problem Solving ▸