Episode 1 — Fundamentals / 1.16 — Using Browser Functionalities in JavaScript
1.16 — Exercise Questions: Browser Functionalities
Practice questions for all four subtopics in Section 1.16.
How to use this material (instructions)
- Read lessons —
README.md, then1.16.a→1.16.d. - Answer closed-book — then reopen the matching lesson.
- Try in Console —
location,history.length,localStorage,fetch('/').then(r=>r.status). - Interview prep —
1.16-Interview-Questions.md. - Quick review —
1.16-Quick-Revision.md.
1.16.a — BOM (Q1–Q10)
Q1. What does BOM stand for in practice, and how does it differ from the DOM?
Q2. What is window.document?
Q3. Name three things you can read from navigator (any valid examples).
Q4. Why is feature detection better than parsing userAgent?
Q5. Is document part of the BOM, the DOM, or both — explain briefly.
Q6. window.innerWidth — what does it measure?
Q7. Hands-on: In Console, evaluate window === window.window.
Q8. Where does setTimeout live by default in browsers?
Q9. What object represents session navigation (back stack)?
Q10. location vs history — one responsibility each.
1.16.b — Location & history (Q11–Q20)
Q11. Read pathname and search from location on any site (Console).
Q12. Difference between location.href = url and location.replace(url)?
Q13. What does history.back() do?
Q14. What does history.go(-2) mean?
Q15. Does pushState load HTML from the network?
Q16. Which event fires when user clicks Back after pushState?
Q17. Set location.hash — what might happen on the page?
Q18. location.assign vs setting href — practical similarity?
Q19. Why should apps avoid infinite history.forward() loops?
Q20. Exercise: Use replaceState to set URL path to /demo without reload (same origin) — observe address bar.
1.16.c — Storage & cookies (Q21–Q32)
Q21. localStorage vs sessionStorage — lifetime difference?
Q22. Are storage values typed or always strings?
Q23. Store object {a:1} in localStorage under key data — show code.
Q24. What is an origin?
Q25. Does localStorage for https://x.com share data with http://x.com?
Q26. Is localStorage.getItem synchronous?
Q27. How does JS read cookies from document.cookie?
Q28. Can JavaScript read HttpOnly cookies?
Q29. Why are cookies often small compared to localStorage?
Q30. When might you still use cookies instead of localStorage for auth-related data?
Q31. localStorage.clear() — what does it affect?
Q32. Hands-on: Set and read sessionStorage key tab — open new tab same site — is value shared?
1.16.d — Fetch (Q33–Q44)
Q33. What does fetch return?
Q34. Does fetch reject on HTTP 500?
Q35. How do you detect success in the fetch + await pattern?
Q36. Name two methods to read the response body.
Q37. Can you call res.json() twice on the same response?
Q38. Write POST JSON body { "name": "Ada" } to /api/users.
Q39. When does fetch’s promise reject?
Q40. What is CORS in one sentence?
Q41. res.status === 204 — is res.ok true?
Q42. Exercise: fetch a public JSON API (e.g. JSONPlaceholder) — log status and parsed data.
Q43. Why check res.ok before res.json()?
Q44. Reflection: Weakest subtopic? Two follow-ups.
Answer hints
| Q | Hint |
|---|---|
| Q12 | replace swaps history entry; href assignment adds navigates normally |
| Q16 | popstate (and you must restore UI) |
| Q22 | Strings — serialize objects |
| Q28 | No — not exposed to document.cookie |
| Q34 | Usually no — check ok |
| Q39 | Network errors, etc. — not most 4xx/5xx |
| Q41 | Yes — 2xx range |
← Back to 1.16 — README