How to Use Conditional Breakpoints to Debug Faster
The bug only shows up on the 347th item in a list, and your breakpoint stops on every single iteration before that. So you press resume, again and again, lose count, overshoot, and start over.

The bug only shows up on the 347th item in a list, and your breakpoint stops on every single iteration before that. So you press resume, again and again, lose count, overshoot, and start over. Conditional breakpoints solve exactly this: the debugger only pauses when an expression you write is true, so you land on the broken case on the first try.
This guide covers how to set conditional breakpoints in Chrome, Firefox and VS Code, the expressions that work best, the closely related logpoint, and the traps that make a condition silently fail.
What conditional breakpoints do
A normal breakpoint pauses execution every time a line runs. A conditional breakpoint attaches a JavaScript expression to that line. Each time the line is reached, the debugger evaluates the expression in the current scope. If the result is truthy, execution pauses. If not, the code keeps running at almost full speed.
That means you can write conditions using any variable visible on that line, such as "item.id === 347", "!user.email" or "response.status !== 200". You get the full power of the language, including method calls like "name.includes('test')".
They are one of several debugger features that most developers never open. Our roundup of browser DevTools features most developers never open covers the rest.
How to set conditional breakpoints in each tool
Chrome and Edge DevTools
- Open DevTools and go to the Sources panel.
- Open the file and find the line you care about.
- Right-click the line number and choose "Add conditional breakpoint".
- Type the expression and press Enter. The marker turns orange instead of blue.
To edit it later, right-click the marker and choose "Edit breakpoint". The Breakpoints pane on the right lists every breakpoint with its condition, which helps when you have set several.
Firefox DevTools
In the Debugger panel, right-click the line number and pick "Add condition". The workflow is nearly identical, and conditions are also editable from the Breakpoints list.
VS Code for Node and front-end code
Right-click in the gutter and choose "Add Conditional Breakpoint". VS Code gives you three options in a dropdown: Expression, Hit Count and Log Message. Hit Count is useful for "pause on the 50th call" without writing a counter yourself. For Node, start your process with the inspect flag or use a launch configuration and the same breakpoints work on the server.
Useful condition patterns
| Goal | Example condition |
|---|---|
| Stop on one record | "user.id === 'u_8812'" |
| Catch bad data | "Number.isNaN(total)" |
| Find a failing request | "!res.ok" |
| Stop late in a loop | "i === 346" |
| Catch an unexpected type | "typeof value !== 'string'" |
| Stop only for one element | "el.dataset.testid === 'checkout-btn'" |
Keep conditions short and free of side effects. A condition like "items.pop()" changes your program state every time it is evaluated, and you will spend an hour chasing a bug the debugger created.
Logpoints: conditional breakpoints that never pause
Sometimes you do not want to stop at all. You want to see a value change across 2,000 iterations. That is what logpoints are for. In Chrome, right-click the line number and choose "Add logpoint", then type something like "'cart total', total, items.length". Each time the line runs, the values print to the Console, without editing the source file.
Logpoints beat a temporary console.log in three ways. You do not have to rebuild or reload with a dev server. You cannot accidentally commit them. And they work in production bundles, as long as you have source maps loaded. If your breakpoints land on the wrong lines in minified code, read why source maps matter more than most developers realize before blaming the debugger.
There is also a trick that combines both ideas: a conditional breakpoint whose expression is "console.log(x), false". It logs and never pauses. Logpoints made this hack mostly unnecessary, but you will still see it in older codebases and blog posts.
Why "just add console.log everywhere" is the wrong default
Plenty of experienced developers say they never use the debugger and print debugging is faster. For a quick check on one value, they are right. As a default habit, it costs more time than it saves.
Every console.log means editing code, waiting for a rebuild and reproducing the bug. If you guessed the wrong variable, you repeat the cycle. With a conditional breakpoint, you pause once at the exact failing case and can inspect every variable in scope, walk up the call stack and run expressions in the console. One pause often answers five questions that would each have needed another log line.
Print statements also disturb timing less than people think, but they still clutter output. On a page logging hundreds of lines per second, the one line you need scrolls away. A condition filters at the source.
The fair compromise: use logs for broad tracing across many functions, and conditional breakpoints once you know roughly where the problem lives. If you do not know which change introduced the bug at all, git bisect can find the commit that broke your build before you start stepping through code.
Common problems and how to fix them
- The breakpoint never hits. The condition may throw an error, which DevTools treats as false. Test the expression in the Console while paused on a normal breakpoint first.
- Variable is undefined. The condition runs before the line executes, so a variable assigned on that same line does not have its new value yet. Move the breakpoint one line down.
- Pages slow to a crawl. A heavy condition on a hot path runs millions of times. Use cheap comparisons or move the breakpoint outside the inner loop.
- Breakpoints vanish after reload. Hashed file names in some build setups change on every build. Enable source maps so DevTools can map breakpoints to the original files.
- Wrong line in transpiled code. Arrow functions and async code compile into different shapes. Use inline breakpoints by clicking the small markers that appear within the line.
Frequently asked questions
How do I add a conditional breakpoint in Chrome?
Open the Sources panel in DevTools, right-click the line number and choose "Add conditional breakpoint". Type a JavaScript expression and press Enter. Execution pauses only when that expression is truthy.
Do conditional breakpoints slow down code?
Slightly, because the expression is evaluated every time the line runs. For most lines the cost is unnoticeable. On a loop running millions of times, keep the condition simple or move the breakpoint.
What is the difference between a logpoint and a breakpoint?
A breakpoint pauses execution so you can inspect state. A logpoint prints a message to the Console and keeps running. Logpoints are best for watching values over many iterations without editing your source code.
More in Dev Tools
Dev Tools
How to Use the DevTools Coverage Tab to Find Dead CSS
A stylesheet on a project I inherited was 184KB minified, one file for the whole site.
Dev Tools
How to Use curl Timing to Find Why an API Request Is Slow
"The API is slow" is one of the least useful bug reports, and also one of the most common.
Dev Tools
Git Rebase vs Merge and How to Choose for Your Team
Your feature branch is three days old, main has moved on by 40 commits, and the pull request page says "This branch is out of...