Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!

All 'debugger' statements should be removed

When do I get this error?

JSHint (before version 1.0.0) will throw the "All 'debugger' statements should be removed" error when it encounters a debugger statement. In the following useless example we attempt to use the debugger statement:

Why do I get this error?

This error is raised to highlight a lack of convention and possible oversight by the developer. The debugger statement is used to tell the environment in which the code is running to open a debugger if one is available and treat the statement as a breakpoint (ES5 §12.15):

Evaluating the DebuggerStatement production may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect.

This can be useful during development to get an insight into how your code behaves, or to inspect the value of variables at runtime. However it's highly unlikely that you want to keep debugger statements in production code. For that reason, JSHint prefers them to be removed.

A note about JSLint

JSLint does not have a dedicated error message for this syntax. Instead it uses one of its more generic messages, "Unexpected '{a}'", in the form of "Unexpected 'debugger'":

In JSHint 1.0.0 and above this warning has changed to "Forgotten 'debugger' statement?". More detail can be found the page dedicated to that message.

James Allardice

This article was written by James Allardice, an enthusiastic young JavaScript developer at Global Personals (we're looking for developers so please apply). He is passionate about writing clean, maintainable JavaScript and uses JSHint every day to help achieve this.

You can follow him on Twitter, fork him on GitHub and find him on Google+.

Proceeds generated by this site are donated to help advance other open source projects

comments powered by Disqus