Breakpoints
A breakpoint is a marker that tells the browser to pause your JavaScript at a specific line. While paused, you can inspect every variable in scope, look at the call stack, and step through the code one line at a time. For React apps, breakpoints are far more precise than scattering console.log() calls, because you see the exact state of props, state and local variables at the moment something goes wrong.
Setting a breakpoint in the browser
Open the developer tools (F12 or Ctrl+Shift+I) and go to the Sources tab in Chrome or Edge, or Debugger in Firefox. Press Ctrl+P to search for your component file by name. Thanks to source maps, which development servers such as Vite generate automatically, you see your original JSX rather than the bundled output. Click a line number to add a breakpoint, then trigger the code, for instance by clicking the button whose handler you want to examine.
The debugger statement
You can also pause from inside your code by writing the keyword debugger. When dev tools are open, execution stops on that line. When they are closed, the statement does nothing. This is handy for code that is hard to find in the file list.
function CartSummary({ items }) {
const total = items.reduce((sum, item) => {
debugger; // pauses here once per item while dev tools are open
return sum + item.price * item.qty;
}, 0);
return <p>Total: {total}</p>;
}
Remove every debugger line before committing, since it is easy to forget one and annoy teammates.
Moving around while paused
| Control | Shortcut (Chrome) | What it does |
|---|---|---|
| Resume | F8 | Run until the next breakpoint |
| Step over | F10 | Run the current line, staying in this function |
| Step into | F11 | Enter the function called on this line |
| Step out | Shift+F11 | Finish this function and return to the caller |
The Scope panel lists local variables, including props you destructured. Hover over any variable in the code to see its value, or type an expression into the Console while paused; it runs in the paused context.
Smarter breakpoints
Right-click a line number to add a conditional breakpoint, such as item.qty < 0. It pauses only when the condition is true, which saves you from clicking Resume dozens of times inside a loop. A logpoint prints a message without pausing, like a temporary console.log() that never touches your file. The Sources panel can also pause on exceptions, or on DOM changes and event listeners.
Why a breakpoint seems to be skipped
If a breakpoint never triggers, the line may simply not run, so check that the event or condition you expect actually happens. Breakpoints can also sit on the wrong file when you open the bundled code instead of the source-mapped original. Another surprise in development is that React's Strict Mode renders components twice to reveal side effects, so a breakpoint in a component body can pause twice per update. That is expected, not a bug in your code.
Remember
Pause where the bug appears, read the Scope panel, step backward through the call stack to see who passed the bad value, and prefer conditional breakpoints inside loops.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.