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.
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."
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.logneeded. - 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".
| Control | Film version | What it does |
|---|---|---|
| Breakpoint | Pause at this scene | Stop before running this line |
| Step over | Next frame | Run this line, stop at the next one |
| Step into | Zoom into this player | Go inside the function called on this line |
| Step out | Back to the wide shot | Finish this function, return to the caller |
| Continue | Play | Run until the next breakpoint |
| Watch | Follow one player | Show an expression's value at every pause |
| Watch expression | Value on her laptop |
|---|---|
| showTime | 2026-11-14T20:00:00.000Z (8 PM UTC) |
| showTime.getHours() | 20 |
| Intl.DateTimeFormat().resolvedOptions().timeZone | Europe/London |
| result | 8:00 PM |
function formatShowTime(showTime) {const hours = showTime.getHours(); // <- breakpoint hereconst 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.
