Search code examples
javascriptgoogle-chrome-devtoolsfirebugmicrosoft-edgefirefox-developer-tools

Set Breakpoint On Code Not Line


I am wondering if there is a way to set a breakpoint on a piece of code, not just on a line of code, in any browser. I am trying to debug some JavaScript and it is quite annoying to have a breakpoint break at the wrong line because I've had to add or delete a line above the breakpoint. So I find that I'm often having to move breakpoints after a code edit.


Solution

  • The debugger statement was introduced in ECMAScript 5.1.

    The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.

    console.log("Before breakpoint");
    debugger;
    console.log("After breakpoint");