Sometimes some developers forgot to remove debugger;
in javascript code, and it produce javascript error on IE.
How can you check (like for the console: if(window.console){console.log('foo');}
) if a debugger exists?
BTW: I don't want to detect if the browser is IE, I want a generic method if possible Thanks,
You cannot.
The best solution would be adding a hook to your version control system to prevent code containing debugger;
statements from being committed/pushed.
Asking your devs to search for debugger;
or at least have a careful look at the diff before committing is also a solution - but not as effective as hard-rejecting in the VCS.
You could attempt to compile a function that declares debugger
as a local variable. If debugger
is reserved as a keyword, the JS engine will throw an error which you can catch.
var debuggerIsKeyword = false;
try {
new Function("var debugger;");
} catch(e) {
debuggerIsKeyword = true;
}
However I'm not sure that knowing whether a keyword exists or not is actually helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With