debugger Statements

By: Dusty Arlia
Published on Sunday, May 5, 2013, 12:30 PM
Last Updated on Tuesday, July 07, 2015 at 8:14 PM
Total Updates: 3

The debugger statement is used for troubleshooting your JavaScript program. These statements will not work unless you have a debugger program running. One of the most popular debugging programs is Firefox's Firebug extension.

Once you have your debugger running, open your webpage. If you have any debugger statements in your JavaScript code, they will cause a breakpoint. A breakpoint will stop the execution of your JavaScript program so you can check the values of variables and examine the call stack.

Here is an example:

function eat(food){
if (food === undefined) debugger;   //temporary line of code used
/*[function body]*/                //used for debugging

In the example above, when you call the eat() function, execution will stop if there is no arguments passed. Then you would be able to use your debugger to inspect the call stack and find out where the function call is coming from.