JS Console Debugging made (a little) easier


Userlevel 1
Badge +2

I love Print Debugging

It’s low class, doesn’t look cool and is possibly woefully less powerful than using an actual debugger, but my goodness printing values to console is easy and useful.

Console.log() is definitely my friend.

That does make things a bit difficult sometimes, especially if I need to manually insert breakpoints and print statements when debugging a piece of code in the browser… Which is why I’m excited to (perhaps belatedly) discover…

The Debugger() function

Put debugger; in your JavaScript function and you’re golden.  As long as there’s an active debugger (like the Browser DevTools), execution will automatically stop when it hits that point, and open the debugger.

function toDebug(foo, bar) {
//Stuff happens
debugger; // << Breaks here
return something;
}

You can check out the docs for the debugger function over at W3C.


0 replies

Be the first to reply!

Reply