Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Statements and Declarations

The debugger statement

Reference for the JavaScript debugger statement: how it pauses execution when developer tools are open, conditional breakpoints in code, and when to remove it.

The debugger statement acts as a breakpoint written into your code. When a debugger is attached (for example, the browser's developer tools are open, or Node.js was started with --inspect), execution pauses at that line and you can inspect variables, the call stack and scopes, then step forward.

When no debugger is attached, the statement does nothing.

JavaScript
function total(items) {
  debugger;
  return items.reduce((sum, i) => sum + i.price, 0);
}

Try it

JS A harmless debugger statement

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Conditional breakpoint pattern

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
debugger;

It takes no arguments and produces no value.

Usage notes

  • Needs developer tools. In a browser, the statement pauses only while the developer tools are open. In Node.js, run with node --inspect-brk file.js or attach an inspector.
  • Conditional breakpoints. Wrapping debugger in an if gives a breakpoint that triggers only for the interesting case. Developer tools also offer conditional breakpoints without editing code.
  • Do not ship it. Remove debugger before releasing. Linters flag it (for example with a no-debugger rule), and leaving it in annoys users who open developer tools.
  • Not logging. console.log() prints values; debugger lets you explore everything in scope interactively.
  • Strict mode does not change its behavior.
  • Source maps. With bundled code, the debugger pauses in the original source if source maps are loaded.
  • Sandboxed iframes such as the live editors on this site run the code but cannot show a debugger for you unless you open the developer tools for that frame.

Browser support

debugger is part of the language and every browser with developer tools honors it.