X

Javascript quick tip debugger statement

Javascript quick tip debugger

Here is Javascript quick tip debugger for Javascript developers, there is a debugger statement in JavaScript, which invokes any available debugging functionality. e.g setting a break point, and if there is no debugging functionality available the statement has no effect.

Let’s say you wish to debug a function

var x = (function f() {          
          var message = 'hello world'; 
          if(typeof window.console !== 'undefined') { 
              console.log(message); 
          } else { 
              alert(message); 
          }
})();

One could then add a debugger; statement into the code to debug the function.

var x = (function f() {
          debugger;  // 

This will automatically launch the debugger in Chrome, Firefox, Opera, Safari and IE.

The debugger statement is part of EMCA script version 5.
For more information
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger

Taswar Bhatti:
Related Post