April 25, 2018

Setting a data dump non-breakpoint in JS debugging



This works for Firefox, Chrome and probably other browsers with integrated developer tools.

If you have programmed on other platforms or debugged with other tools, you may be missing a very handy feature: the ability to set a breakpoint that really dones't break but dumps the value of some variable or expression when it's hit.

The truth is that there is no such explicit feature. But you have it implicitly. Let me explain myself:

The trick is simple: use a conditional breakpoint instead, with a condition such as console.log(yourVariable).


When the relevant line is hit, since that expression will evaluate to false, there will be no break, but, given the expression is evaluated indeed, console.log (or any other of its family) will be called, effectively dumping your value to the console.