Async and fetch

Wait for slow work with promises and async/await.

Network calls take time, and JavaScript does not stop and wait for them. A promise stands for a result that will arrive later, and await pauses one function until it does.

  • fetch only rejects on a network failure, so check res.ok for errors such as 404.
  • Use await only inside an async function.
  • Use Promise.all to run several calls at the same time.
โ† Changing the pageErrors and debugging โ†’