Breakpoint
A pause point set in developer tools.
Breakpoints pause running code so you can inspect variables, call stack and execution flow at the exact line that matters.
function calculateTotal(items) {
debugger;
return items.reduce((sum, item) => sum + item.price, 0);
}
Errors & Debugging
A breakpoint pauses code in the browser developer tools. While paused, you can inspect variables, step through lines and see the call stack.
The debugger statement is a breakpoint written in code. It pauses only when developer tools are open.
Use breakpoints when logs are not enough. They are especially useful for conditions, loops, event handlers and code that changes state over time.
A pause point set in developer tools.
A statement that pauses execution when devtools are open.
Run the current line and pause at the next one.
Shows how execution reached the paused line.
Examples
for (const record of records) {
if (record.status === "ready") {
debugger;
}
}
function render() {
debugger;
updatePage();
}
// This should not be committed accidentally.
Code patterns
These examples focus on the debugging patterns you will reuse: safe parsing, throwing, custom error types, console inspection, breakpoints and async failure handling.
Pause at the exact line during development.
function render(records) {
debugger;
return records.length;
}
Pause only when a condition is true.
// In DevTools, set a breakpoint condition: // record.status === "ready"
Breakpoints are useful inside loops.
for (const record of records) {
if (!record.title) {
debugger;
}
}
debugger should not stay in production code.
// Search before commit: // rg "debugger"
Rules that matter
Debugging starts before something breaks. Clear error types, helpful messages and visible failure states make the code easier to repair.
Pause when you need real values, not guesses.
It explains how execution reached this line.
They reduce noise in loops and repeated events.
Step over, into and out answer different questions.
They are development tools, not production code.
Logs show history; breakpoints show current state.
Production thinking
Breakpoints turn debugging from print-and-guess into direct inspection.
Breakpoints help inspect focus, keyboard and ARIA state changes at the moment they happen.
Production builds should block committed debugger statements through linting or review.
Breakpoints help find render paths that fail before content reaches the page.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
A JavaScript feature is not production-ready until you know how it fails and how you will inspect that failure.