Browser DevTools & Debugging

The browser's built-in tools for inspecting and debugging what a page is really doing, beyond what it shows.

What is it?

Every major browser includes DevTools, usually opened with a keyboard shortcut or a right-click "Inspect." The visible page often isn't enough to understand or fix a problem. You need to see the structure underneath, watch code run, inspect network traffic, and catch errors as they happen.

The panels you'll use most:

  • Elements shows the live DOM tree (not the original HTML source) and the computed CSS for the selected element. You can edit either on the fly to experiment.
  • Console shows messages logged by JavaScript and reports errors and warnings as they happen. It's also a live prompt for running code against the current page.
  • Network lists every request the page made: what was requested, how long it took, and what came back. It's usually the first place to look when something won't load or loads slowly.
  • Sources shows the JavaScript files running on the page and lets you set breakpoints, points where execution pauses so you can inspect variables and step through code line by line instead of guessing from logs.

Explain like I'm 10

DevTools is like opening the hood of a car instead of looking at the dashboard. The dashboard (the rendered page) tells you the car is running; under the hood you can see which part is misbehaving.

Examples

Inspecting and editing the live DOM

// In the Elements panel, selecting an element shows
// its live HTML and the CSS rules currently applied to it.
// Editing text or a style there updates the page instantly,
// without changing any actual file on disk.

A quick way to test a visual tweak, like a new color or margin, before writing it into a CSS file. You're editing the live DOM, not the source.

Setting a breakpoint in Sources

function calculateTotal(items) {
  let total = 0;
  for (const item of items) {
    total += item.price; // <- breakpoint set on this line
  }
  return total;
}

A breakpoint on the marked line pauses execution each time that line is about to run, so you can check total and item right there instead of sprinkling console.log everywhere.

How it works

DevTools is built into the browser and has privileged access to the page's internals. It can:

  • read the live DOM and computed styles (Elements)
  • log messages, catch errors, and run any code in the page's context (Console)
  • watch every network request the page makes (Network)
  • pause JavaScript at specific lines (Sources)

The page doesn't need any special debugging code; the browser offers this for every page by default.

Why does it exist?

Looking at the rendered page isn't enough to build or fix anything nontrivial. You need to see structure, styling, network activity, and code execution that never show up on screen. Because every browser has these tools for any page, debugging is a normal part of web work, not something that needs separate specialized tools.

When to use it

  • Elements: something looks wrong and you need the applied styles.
  • Console: checking for errors or quickly testing a snippet.
  • Network: something isn't loading, loads slowly, or you need to see what a request sent or received.
  • Sources and breakpoints: you need to see exactly what some JavaScript does, step by step.

When not to use it

DevTools is for debugging and inspection, not permanent changes. Live edits in the Elements or Sources panel vanish on reload, since they never touch the real source files. For intended, permanent behavior, the source code is the source of truth.

Common mistakes

  • Editing something in the Elements panel and expecting it to survive a reload, when live edits vanish on refresh.

  • Skipping the Network panel when debugging a 'blank page' or missing data, when a failed or slow request is often the cause.

  • Relying only on scattered console.log statements for a tricky bug instead of pausing at a breakpoint to inspect state.

Practice exercises

  1. Easy:

    Open DevTools on any webpage, select an element in the Elements panel, and find one CSS rule applied to it.

  2. Medium:

    Open the Network panel, reload a page, and find the largest resource downloaded.

  3. Hard:

    Set a breakpoint in a JavaScript function on a real page, trigger it, and step through the code line by line while watching a variable change.

Interview questions

What's the difference between the Elements panel and viewing a page's HTML source?

The Elements panel shows the live DOM, which JavaScript may have changed since load. 'View source' shows the original HTML as the server first sent it.

What is a breakpoint, and why use one instead of console.log?

A breakpoint pauses JavaScript at a specific line so you can inspect every variable and step through the code. That's often faster and more thorough than adding and removing log statements.

When would you check the Network panel while debugging?

When something isn't appearing, is loading slowly, or you need to check exactly what a request sent or received. It's the main place to see all of a page's network activity.