How do you pause code execution at a specific line using the browser DevTools?
Short answer
Insert a debugger statement in your code, or click in the gutter of the Sources panel to set a breakpoint. When execution reaches that line, DevTools pauses so you can inspect variables and step through code.
Advertisement
AModel answer
Insert a debugger statement in your code, or click in the gutter of the Sources panel to set a breakpoint. When execution reaches that line, DevTools pauses so you can inspect variables and step through code.
function calculateTotal(items) {
debugger; // execution pauses here when DevTools is open
return items.reduce((sum, i) => sum + i.price, 0);
}Real-world example
Pausing mid-function to inspect why a total is calculating incorrectly.
Likely follow-ups
- What's the difference between 'Step Over', 'Step Into', and 'Step Out'?
Related topics