Request data and interpret responses.
- fetch
- Request
- Response
- status
- JSON
fetch returns a promise for a response. A response can have an unsuccessful HTTP status while the fetch promise still fulfills, so check response.ok. Parsing JSON is another asynchronous step. Keep loading, success, empty, and error UI states distinct.
Treating every fulfilled fetch as success hides 404 and 500 responses.
Fetch a local JSON file, display a list, and add a clear error state for a missing file.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- Explain the core idea in your own words without reading the code.
- Change one input and predict the output before running it.
- Test one boundary or failure case, then record what you changed.
Run python3 -m http.server 8000 from the JavaScripts folder, then open this lesson through http://localhost:8000/. Fetch, modules, storage, history, and workers can behave differently or fail under file URLs.