Using a Debugger

3.Pause the Film, Frame by Frame

A

In this chapter

We'll learn to use a debugger properly — breakpoints, stepping through code line by line, watch variables and the call stack panel — explained as pausing a film and watching it frame by frame.

12–14 min

The Problem in Real Life

Until now, Anna debugged the way most beginners do: adding console.log("here") everywhere, running the app, deleting the logs, adding new ones. It works, slowly.

John shows her the other way. He clicks to the left of a line number in VS Code. A red dot appears. "That's a breakpoint. Now the program will stop right there and let you look around — at everything, not just the one value you remembered to print."

J

console.log shows you one photo. The debugger lets you pause the whole film.

John

Printing Values Everywhere vs. Pausing and Looking Around

console.log shows one value

You only see what you remembered to print — and you rerun the app every time you want to see more.

Code runs too fast to watch

A function runs in microseconds. You need a way to slow it down to human speed.

The bug is in the details

To see exactly which line produces the wrong value, you need to watch values change line by line.

Breakpoints, Stepping and Watch Variables

The film analogy: imagine trying to spot a mistake in a football match that happens in half a second. Watching at normal speed, you miss it. So you pause the replay at the right moment, then go frame by frame, looking at every player. A debugger does exactly this for your program.

In Act 16 we met the debugger and breakpoints briefly. Now let's use them for real.

  • Breakpoint — where to pause: a breakpoint is a marker on a line (the red dot). When the program reaches that line, it stops before running it. Everything is frozen: every variable, the whole call stack. Put breakpoints where the wrong value might first appear.
  • Stepping — frame by frame: once paused, you move forward on purpose. Step over runs the current line and stops at the next one (if the line calls a function, it runs the whole function without going inside). Step into goes inside the function call on this line. Step out finishes the current function and stops back where it was called. Continue runs normally until the next breakpoint.
  • Variables panel — everything on the pitch: while paused, the debugger shows every variable in scope and its current value — no console.log needed.
  • Watch variables — the players you're following: a watch is an expression you pin to a panel, and the debugger re-checks its value every time it pauses. You can watch a variable (showTime), part of one (venue.name), or any expression (showTime.getHours()).
  • Call stack panel — how did we get here: the same call stack you saw in the stack trace (chapter two), but live. Clicking a level shows that function's variables at that moment.
  • Conditional breakpoints — pause only when it matters: if a function runs 10,000 times, pausing every time is useless. A conditional breakpoint only pauses when an expression is true, like eventId === "riverside-arena-1114".
Table — Debugger controls
ControlFilm versionWhat it does
BreakpointPause at this sceneStop before running this line
Step overNext frameRun this line, stop at the next one
Step intoZoom into this playerGo inside the function called on this line
Step outBack to the wide shotFinish this function, return to the caller
ContinuePlayRun until the next breakpoint
WatchFollow one playerShow an expression's value at every pause
Table — What Anna's watch panel showed
Watch expressionValue on her laptop
showTime2026-11-14T20:00:00.000Z (8 PM UTC)
showTime.getHours()20
Intl.DateTimeFormat().resolvedOptions().timeZoneEurope/London
result8:00 PM
The function under the breakpoint
function formatShowTime(showTime) {
const hours = showTime.getHours(); // <- breakpoint here
const minutes = showTime.getMinutes();
const suffix = hours >= 12 ? "PM" : "AM";
const h12 = hours % 12 || 12;
return `${h12}:${String(minutes).padStart(2, "0")} ${suffix}`;
}

getHours() returns the hour in the timezone of the machine running the code — not the venue's timezone.

Anna's debugging session: she puts a breakpoint inside formatShowTime and opens the Riverside Arena page on her laptop. The program pauses. The variables panel shows showTime = 2026-11-14T20:00:00.000Z — that's 8:00 PM in UTC (the world's reference clock), and London in November is on UTC, so it's correct. She steps over one line at a time and watches hours become 20, then the result become "8:00 PM". Correct.

The suspicious line: the line that sets hours is const hours = showTime.getHours();. She adds a watch: Intl.DateTimeFormat().resolvedOptions().timeZone — the timezone this machine is using. It says "Europe/London". That's when she understands: getHours() doesn't ask the venue what time it is. It asks the computer the code is running on. On her laptop that's London. On the production servers, the logs said Berlin.

Still a hypothesis: "So prove it," John says. "If you're right, you should be able to make your own laptop show 9:00 PM." That's the next chapter: debugging as a method, not luck.

Key Takeaway

A debugger lets you pause a running program like a film and go frame by frame. A breakpoint says where to pause; step over, step into, step out and continue control the playback; the variables panel shows everything, watch expressions follow what you care about, and the call stack panel shows how you got there. Conditional breakpoints pause only when it matters.

Why This Matters

Debuggers turn guessing into looking. Instead of adding and removing print statements over and over, you see every value at the exact moment it goes wrong. Every editor and browser has one, and engineers who use them well find bugs many times faster — especially in code they didn't write.

Anna has a strong suspicion: the code uses the machine's timezone. But suspicion isn't proof. A professional debugger follows a method: reproduce, isolate, form a hypothesis, test it.