Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Add a JavaScript breakpoint programmatically

When working on JavaScript code you’ll probably find yourself riddling the code with console.log-statements when something is not working the way that you’re expecting.

But did you know that there is a debugger statement available? It has invokes any available debugging functionality. To put it otherwise: you can programmatically set a breakpoint for your debugger. It should work in any browser.

function potentiallyBuggyCode() {
    debugger; //the debugger wil stop here

Here’s the documentation on the debugger-statement on MDN.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band. He loves waffles and butterflies.