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
1 2 3 4 5 6 7 8 |
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.
1 2 3 4 5 6 7 8 9 |
var x = (function f() { debugger; // <- statement to make a breakpoint var message = 'hello world'; if(typeof window.console !== 'undefined') { console.log(message); } else { alert(message); } })(); |
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
Leave A Comment