Fork me on GitHub

JSLint Error Explanations

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


Read only

When do I get this error?

JSLint and JSHint will throw the "Read only" error when they encounter an attempt to assign a value to built-in native object. In the following example we attempt to overwrite String constructor function:

As of July 2013, JSLint will also throw the "Read only" error when it encounters an assignment to an exception parameter. This previously generated the "Do not assign to the exception parameter" warning. See the page for that message for more details on the reasoning behind it:

Why do I get this error?

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

It is perfectly valid to overwrite any of the native built-in functions, but there are limited use cases for it. JSLint and JSHint both forbid this practice completely and do not provide an option to allow it.

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

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

JSHint uses the same list, but adds a few extra identifiers to it:

hasOwnProperty Map NaN Set WeakMap

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 W020. This means you can tell JSHint to not issue this warning with the /*jshint -W020 */ 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