Headers are case-insensitive, JSON is lossy
The Headers object lowercases names. In JSON, the date became a string, note vanished, and the Set became an empty object.
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
application/json
application/json
true
[ [ 'content-type', 'application/json' ], [ 'x-request-id', 'abc123' ] ]
{"item":"Tea","placedAt":"2024-01-15T10:30:00.000Z","tags":{}}
string false {}