The first time I saw the Visual Studio JavaScript debugger work, I swear I heard the theme from 2001. It was like watching apes learn to use tools.
Debug by Print Statement Alert Box
Back in the dark times, the only way to debug JavaScript was via the handy alert box (you know, that annoying popup box complete with irritating horn.) It was, and continues to be, the web scripting equivalent of debug by print statement.
Still, it worked well enough. despite being slow and painfully annoying; however, more recently, several browsers have implemented consoles which can record logging statements. Because it does not interrupt the code as it’s being run, it’s a lot better than debug by alert box, but ultimately, it’s still debug by print statement.
Microsoft Visual Studio
Then there’s Visual Studio.
Perhaps the finest IDE in the world offers a simple way to step through your code, examine the value of variables, and treat your scripting code like it was C#, VB.NET, or C++. All you need to do is add this statement to your code wherever you would like a breakpoint:
debugger
Then open (or create) a website project in Visual Studio that contains a copy of your JavaScript file (make sure that that the Javascript is obfuscated).
Make sure your project is in Debug mode, press the Start Debugging button and execute your script file in a browser.
When the script file hits the debugger line, it will break into Visual Studio and you can look at variable values, Step In, Step Over and Continue to your heart’s content.
There you go!
Happy debugging!