Lesson 3.4Lesson 15 of 24
Browser APIs
Given a scenario and requirements, utilize browser specific APIs.
Key points
- 1window is the global object in a page; document is the loaded page; location reads the URL, and assigning a new URL to it loads that page.
- 2history.pushState changes the URL and adds a history entry without a reload. Going back and forward then fires popstate on window.
- 3localStorage keeps strings per origin across restarts and tabs; sessionStorage keeps them per tab until it closes. Store objects with JSON.stringify.
- 4fetch returns a promise that rejects only on a network error or an abort. A 404 or 500 still fulfils, so check response.ok.
- 5setTimeout and setInterval return ids for clearTimeout and clearInterval. An AbortController signal cancels a fetch.
What the exam guide checks here
Objective wording from the exam guide (English).
- 3.4.K1window, document, location and history; localStorage and sessionStorage
- 3.4.K2fetch, timers, and other Web APIs available in the browser but not in the language
- 3.4.S1Choose the browser API that meets a requirement
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 3.4 · 12 questions