[Javascript] Break Your Code With Debugger Statement


In this post, we will know more about Debugger Statement available in the javascript library. Many Javascript developers may not aware of Debugger Statement. I generally believe most of the javascript developer use any of the below four methods for client side debugging.


In which here, we are primarily going to talk about Debugger Statement. Before that, The Console object provides access to the browser's debugging console and it has many inbuilt methods available with it. Some of the example methods are

console.trace();
console.warn();
console.log();
console.info();
console.error();
console.clear();
You can use these methods to display differentiate the console message. Check this URL to know more about console object.  



Debugger Statement:

The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.

Syntax:
debugger;

Code:

function potentiallyBuggyCodeAvailable(){
   code;
   debugger;
}

Please find the above code, When the debugger is invoked, execution is paused at the debugger statement. It is like a breakpoint in the script source.

Javascript Debugger

In the above code, when submit button is clicked it will call sum() method and the code will break where the debugger statement is added.


Please find the above screenshot, the code got broken where the debugger statement is added. It will be really helpful under certain circumstances.

Next Article : [Javascript] Exception Handling with Try...Catch Block

If you enjoyed this article, Please share it with your developer friends and in social media.

Comments