Please help Ukrainian armed forces! Official Fundraising

How to Set Programmatic Breakpoint in JavaScript

1 1 1 1 1 How to Set Programmatic Breakpoint in JavaScript5.00Rating 5.00 (1 Vote)

Modern browsers hav vast debugging capabilities. They include variable watching, code un-minifying, regular and conditional JavaScript code breakpoints. If you want to set a breakpoint to code, you need to open browser debugging console, find the subject code line and then just press the button "Place breakpoint"

But what if you want to place breakpoint in code when you actually write the code? This is much easier when you write your own code, no need to locate the code line twice (in editor and in debugger), it is persistent and more clean.

So, to place progammatic breakpoint in your JavaScript code, just use the debugger instruction:

debugger;

If the JavaScript debugger is active (i.e. developer window is open), the browser will stop on this code line.

 

You can even place conditional breakpoints:

if (x==5) breakpoint;

The mentioned breakpoint will stop the debugger only if x can be equalized to 5. 

 

  

Tuesday the 23rd.