Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Memory Management and DevTools  ›  Lesson

Debugging with DevTools

Debugging Issues 10 minBrowser DevTools is a real application, not a page: the Elements tab shows the live DOM, Console runs JS and shows logs, Sources sets breakpoints to pause and step through code, Performance records a timeline of what's slow, and Memory takes heap snapshots to compare and spot leaks.

Debugging with DevTools

In short: browser DevTools (open it with F12, or right-click → Inspect) is a set of tools built into the browser itself, working on the page you have open — so this lesson describes what you'll see and click, rather than code to run. Five tabs answer five different questions: Elements (what's actually on the page right now), Console (run JS, see logged output), Sources (pause and step through code with breakpoints), Performance (record a timeline of what's slow), and Memory (take heap snapshots to compare and spot leaks). This lesson is read-only — open DevTools on any page and follow along.

A DevTools panel with five tabs — Elements, Console, Sources, Performance, Memory — each answering a different question: what's on the page, logged output and a live JS line, breakpoints and stepping, a slow-timeline recording, and heap snapshots for leaks; a note that the debugger keyword pauses code exactly like a Sources breakpoint; this is a real desktop app, open it with F12 and click around

Pausing code exactly where you need to look

The Sources tab is where most real debugging happens: click a line number to set a breakpoint, then reload or trigger the code path. When execution reaches that line, the whole page freezes, and you can inspect every variable in scope, hover over expressions to see their current value, and step through the following lines one at a time with the play/step controls. The debugger; statement, written directly in your code, does the exact same thing — it pauses execution there as if you'd clicked to set a breakpoint on that line, without needing DevTools open in advance.

function applyDiscount(total, code) {
  debugger; // execution pauses here once DevTools is open
  if (code === "SAVE10") return total * 0.9;
  return total;
}

A breakpoint answers "what is actually happening at this exact moment," which is a different, often more powerful question than "what did I decide in advance to print with console.log."

Reading what's slow, not just what's wrong

The Performance tab records a timeline while you interact with the page, then breaks that timeline down into what the browser spent time on: scripting, rendering, painting. A tall block of "scripting" time pointing at one function is the browser telling you exactly where to look first, instead of guessing which part of the code is slow.

The Console and Elements tabs matter here too, in smaller ways: the Console is where most console.log output actually lands, and where you can type a line of JS to try against the live page; Elements shows the DOM as the browser currently has it — which can differ from the original HTML once JavaScript has modified it.

Comparing two moments in memory

The Memory tab takes a heap snapshot — a complete picture of every object currently allocated, and what's keeping each one reachable. Taking two snapshots at different points (say, before and after repeating some action several times) and comparing them is the standard way to confirm a suspected leak: if the same kind of object keeps showing up with a growing count between snapshots, something is holding onto objects it should have let go of.

🎯 Your turn

Explain what a breakpoint in the Sources tab lets you do that scattering console.log statements through your code does not, and why you might still prefer console.log for some situations.

Quick practice

quick drill

Which DevTools tab do you use to pause code execution at a specific line and inspect variables?

quick drill

What does the debugger; statement do when written directly in your code?

quick drill

What is a heap snapshot, in the Memory tab, mainly used for?

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainBreakpoint vs console.log

Explain what a breakpoint in the Sources tab lets you do that scattering console.log statements through your code does not, and why you might still prefer console.log for some situations.