JavaScript · Middle · Question 63 of 75

Why do you need two awaits here?

const res = await fetch("/api/user");
const user = await res.json();

Explanation

The body may still be streaming when headers are available. Check res.ok before parsing, because 4xx/5xx responses don't reject.

Further reading

Problem with a question

JavaScript · Middle · question 63

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz