TIL: debugger Javascript statement


Today I learned is just going to be me making a note of something interesting that I learned that might be useful for other people. I actually learned this two days ago from a coworker, but it is something I don’t want to forget.

Apparently modern browsers (at least Firefox and Chrome which is what I tested on) support putting a statement anywhere in your javascript file that is just:

debugger;

When you use that and have the developer tools open in the browser when that line of code is hit, it acts as a breakpoint. So often the browser is opening a ton of js files and navigating in the dev tools and finding a line number to break on is a bit of work. But now I just drop this in and then grunt serves up the new page and there I am in the browsers debugger ready to debug the code. I found this very helpful for my work flow so I figured I would share it, in case it can help someone else.