JavaScript · Async JavaScript

fetch()

Starts an HTTP request and resolves with a Response. It rejects only on network failure, not on 404 or 500.

Syntax
await fetch(url)

Example

Try it

Notes

Check response.ok yourself. A 500 response still fulfils the fetch promise.

More in this group

AbortController async / await clearTimeout() Event loop order Promise Promise.all() Promise.allSettled() Promise.any()

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course