Repaso
Español

What does await do inside an async function?

async function loadUser() {
  const res = await fetch("/api/user");
  const user = await res.json();
  return user;
}

Options

  1. It blocks the whole browser until the request ends
  2. It pauses this function until the promise settles (Correct option)
  3. It turns the request into a synchronous request
  4. It retries the request until it finally works

Answer

Pauses this function until the promise settles, without freezing the rest of the page

Why

await waits for a promise and gives you its value, so async code reads top to bottom like normal code.

Only THIS function pauses; the browser keeps handling clicks, animations and other code meanwhile.

If the promise rejects, await throws, so wrap it in try/catch to handle errors. Note: an async function itself always returns a promise.

Remember

await = pause this function, not the page.

Key terms

Practice this question in Repaso