The DOM and Browser APIs

Understand what React does for you by manipulating the DOM directly, handling events and using storage and URL APIs.

Beginner · about 6 hours · difficulty 2/5

Learn first: JavaScript Fundamentals, Semantic HTML

React hides the DOM, but it does not remove it. Knowing what happens underneath helps you debug rendering, events and performance.

The DOM

The browser turns HTML into a tree of nodes. JavaScript can query nodes (querySelector), change text and attributes, add and remove elements, and toggle classes.

Events

  • addEventListener for click, input, submit and keydown.
  • Event bubbling and delegation: one listener on a list instead of one per item.
  • preventDefault on form submit so you can send data with fetch instead of reloading.

Useful browser APIs

  • localStorage and sessionStorage: small key-value storage. Never store auth tokens or secrets here.
  • URL and URLSearchParams: read and build query strings for filters and pagination.
  • History API: how client-side routers change the URL without reloading.
  • IntersectionObserver: lazy loading and infinite scroll.

Pitfalls

  • Building large UIs with manual DOM updates. It quickly becomes unmanageable, which is exactly why React exists.
  • Attaching listeners inside loops and never removing them.

You are ready to move on when you can build a small todo list in plain JavaScript that adds, completes and deletes items and persists them in localStorage.

Key concepts

  • Selecting and updating elements
  • Events and listeners
  • Bubbling and delegation
  • Form submit and preventDefault
  • localStorage and sessionStorage
  • URL and URLSearchParams
  • IntersectionObserver

Mini project

Build a vanilla JavaScript expense splitter for a hostel trip: add expenses in rupees, assign who paid, show who owes whom, and save state in localStorage.

Check yourself

You have a list of 500 items each needing a click handler. Why is event delegation a better choice than 500 listeners?

Free resources