Fork me on GitHub

JSLint Error Explanations

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


Redefinition of '{a}'

When do I get this error?

JSHint will throw the "Redefinition of '{a}'" error when it encounters an attempt to declare a variable whose identifier is the same as that of a built-in native object. In the following example we attempt to declare a variable with the identifier String:

Why do I get this error?

This error is raised to highlight a potentially dangerous piece of code. Your code may run fine if you do not fix this error, but it will be confusing to others, especially at first glance to someone quickly searching through your script, and it will be likely to break third party scripts.

It is perfectly valid to reassign (and thereby override) any of the native built-in functions, but there are limited use cases for it. JSHint forbids this practice completely and does not provide an option to allow it.

The list of read only functions used by JSHint is as follows:

Array Boolean Date decodeURI decodeURIComponent encodeURI encodeURIComponent
Error eval EvalError Function hasOwnProperty isFinite isNaN
JSON Map Math NaN Number Object parseInt
parseFloat RangeError ReferenceError RegExp Set String SyntaxError
TypeError URIError WeakMap

See the article on the "Read only" error for more discussion. Note that JSLint defines this error message but never actually uses it.

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W079. This means you can tell JSHint to not issue this warning with the /*jshint -W079 */ directive.


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