Debugging With Breakpoints: A Practical Guide
Breakpoints let you pause a program and inspect its state. Learn conditional breakpoints, watch expressions, and how to debug without print statements.
By Velloreth
What a breakpoint does
A breakpoint pauses your program at a chosen line. While paused, you can inspect everything: the values of variables, the call stack, the state of objects, the contents of collections.
This is fundamentally different from a print statement. A print statement shows you one value at one moment. A breakpoint shows you the entire state, and lets you explore it interactively.
function calculateDiscount(cart, user) {
const subtotal = cart.items.reduce((sum, i) => sum + i.price * i.qty, 0);
const rate = user.isPremium ? 0.2 : 0.1; // ← breakpoint here
return subtotal * rate;
}
Pause on that line and you can inspect cart, user, subtotal, and every property of each — without adding a single line of code.
The debugger panels
Most debuggers show the same four things.
Variables. The current values in scope, expandable for objects and arrays.
Call stack. The chain of function calls that led here, with the current line in each frame.
Watch expressions. Custom expressions you want to track, re-evaluated at each pause.
Breakpoints. The list of active breakpoints, which you can enable, disable, or edit.
The call stack is the panel people underuse. When a bug appears in a function, the question is usually “how did we get here?” — and the stack answers it directly. Clicking a frame shows the variables in that scope, so you can trace how a bad value propagated.
Conditional breakpoints
The most valuable feature for real debugging. A conditional breakpoint pauses only when an expression is true.
for (let i = 0; i < 1_000_000; i++) {
process(items[i]); // breakpoint with condition: i === 5000
}
Without the condition, you would press continue 5,000 times. With it, the debugger runs at full speed until the condition holds.
Useful conditions:
i === 5000— a specific iteration.user.id === 'abc123'— a specific record.items.length === 0— an edge case.total < 0— an invalid state.error !== null— a failure path.
The condition is evaluated in the current scope, so you can reference any variable available at that line.
Logpoints
A logpoint logs a message instead of pausing. It is a print statement you do not have to edit into the code.
// logpoint message: "processing item {item.id}, total so far {total}"
The debugger prints the interpolated message and continues. You can add twenty logpoints, observe the output, and remove them all without touching the source.
This is the best of both worlds: the observability of print statements with the non-invasiveness of breakpoints. Use logpoints when you want to see a sequence of values without stopping.
Stepping
Once paused, you control execution.
| Action | What it does |
|---|---|
| Continue | Resume until the next breakpoint |
| Step over | Run the current line, pause at the next |
| Step into | Enter the function being called |
| Step out | Run to the end of the current function |
| Restart | Restart the program with the same breakpoints |
| Pause | Interrupt a running program |
Step over is the default. It runs the current line without descending into function calls, which keeps you at the level you are investigating.
Step into is for when the bug is inside the function being called. Use it deliberately, because it is easy to end up deep in library code.
Step out is the escape hatch. When you have stepped into something irrelevant, step out to return to your code.
Breakpoints on exceptions
The most powerful technique for crashes. Instead of guessing where the failure happens, tell the debugger to pause when an exception is thrown.
// VS Code launch.json
{
"type": "node",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/index.js",
"stopOnEntry": false
}
Then enable “Break on All Exceptions” or “Break on Uncaught Exceptions” in the debug panel.
The debugger pauses at the exact moment of failure, with the full call stack and all variables intact. This is far more informative than reading a stack trace after the fact, because you can inspect the state that caused the failure.
The distinction matters:
- Uncaught exceptions — pause only when nothing handles it. Fewer false positives.
- All exceptions — pause on every throw, including ones that are caught and handled. Useful when a library swallows an error you care about.
Debugging a running process
You do not have to start the program under the debugger. Most runtimes support attaching.
Node:
node --inspect-brk=0.0.0.0:9229 server.js
Then attach from your editor. --inspect-brk pauses on the first line, giving you time to attach; --inspect does not.
Python:
python -m debugpy --listen 5678 --wait-for-client app.py
Go:
dlv debug ./cmd/server
This is how you debug a server that only fails under real traffic, or a process that has been running for hours.
Debugging in the browser
Browser DevTools have the same features, plus a few extras.
Sources panel — set breakpoints in your code, and in the DOM.
Event listener breakpoints — pause on any click, keypress, or network event.
DOM breakpoints — pause when an element’s attributes, children, or subtree change. Invaluable for finding what is mutating the DOM unexpectedly.
XHR/fetch breakpoints — pause on requests matching a URL pattern.
debugger; statement — a breakpoint in code. It works in any browser and pauses when DevTools is open. Useful for code you cannot easily click to.
When print statements are better
Breakpoints are not always the right tool.
Timing-sensitive bugs. Pausing changes timing, which can make a race condition disappear. Print statements with timestamps are better for concurrency bugs.
Production. You cannot attach a debugger to production. Structured logging is the tool there.
Long-running processes. Pausing a process that holds a lock can deadlock the system.
Simple checks. If you want to know one value once, a print is faster than setting up a debugger.
Distributed systems. A breakpoint pauses one process; the others keep running and may time out. Logging with correlation ids is better.
The judgement: use breakpoints for logic bugs in a single process, and logging for timing, production, and distributed problems.
A debugging workflow
1. Reproduce reliably. A bug you cannot reproduce is a bug you cannot debug. Find the smallest input that triggers it.
2. Form a hypothesis. Where do you think the problem is? What value do you expect, and what do you suspect it actually is?
3. Set a breakpoint at the hypothesis. Not at the start of the program — at the place you suspect.
4. Inspect. Check the variables. Is the value what you expected? If yes, the bug is later; if no, it is earlier.
5. Move the breakpoint. Narrow the range by bisecting. This is binary search applied to debugging.
6. Fix and verify. Once you find the cause, fix it and confirm the reproduction no longer triggers.
The bisection step is what makes this fast. Each inspection halves the search space, so a bug in a 1,000-line flow takes about ten inspections to locate.
Practical guidance
- Set breakpoints where you suspect, not at the start.
- Use conditional breakpoints for specific iterations or inputs.
- Use logpoints instead of editing print statements in.
- Check the call stack — it often answers “how did we get here?”.
- Break on exceptions for crashes.
- Use watch expressions for values you check repeatedly.
- Bisect by moving the breakpoint, rather than stepping through everything.
- Fall back to logging for timing, production, and distributed bugs.
For the related techniques, see debugging strategies that work and rubber duck debugging. For the tooling, vscode complete guide and incident response for solo developers.
Quotable summary
A breakpoint pauses execution at a chosen line so you can inspect variables, the call stack, and the program state at that moment, which is fundamentally more informative than a print statement showing one value. Conditional breakpoints fire only when an expression is true, which is essential when a bug occurs on one iteration out of a million. The call stack panel shows how execution reached the current line and often answers the real question. Logpoints log without pausing, giving the observability of print statements without editing the code. Breakpoints beat print statements for logic bugs in a single process, while logging is better for timing-sensitive, production, and distributed problems, where pausing changes behaviour or is impossible.