Status codes grouped by their first digit
HTTP is the request-and-reply conversation between the browser and a server: every request has a method, a URL and headers, every reply has a status code, headers and a body, and the browser's CORS rules decide which replies your JavaScript may read.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a function isRetryable(status) that returns true for 408, 429 and any 5xx status, and false otherwise. Log the result for 404, 429 and 503.
Build a Headers object with Accept: application/json and Authorization: Bearer abc, then log every header name, one per line.
Explain it without notes
What are the parts of an HTTP request and of an HTTP response?
Explain the status code families and give two examples of each.
What is the same-origin policy, and how does CORS relax it?
When does the browser send a preflight request, and why?
Preview
Console
Nothing logged yet.Expected console output
200 success: use the body
201 success: use the body
204 success: use the body
304 redirect or cached: the browser usually handles it
400 client error: fix the request, don't retry as-is
401 client error: log in again
404 client error: fix the request, don't retry as-is
429 client error: too many requests, wait and retry
500 server error: a retry later may work
503 server error: a retry later may work