Fork me on GitHub

JSLint Error Explanations

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

Attempting to override '{a}' which is a constant

When do I get this error?

JSHint will throw the "Attempting to override '{a}' which is a constant" error when it encounters an assignment to a constant that is not preceded by the const keyword, when the esnext option is set to true. In the following example we declare a constant MY_CONST and assign a value to it, and then attempt to change its value:

Why do I get this error?

This error is raised to highlight a possible fatal JavaScript Type Error. Your code is likely to fail if you do not fix this issue.

The current implementation of the const statement is a Mozilla-specific extension. It is not found in the ECMAScript 5 specification and should not be relied upon for widespread support.

The Mozilla Developer Network gives the following details for the const keyword:

The value of a constant cannot change through re-assignment, and a constant cannot be re-declared. Because of this, although it is possible to declare a constant without initializing it, it would be useless to do so.

You can fix this issue by removing any assignments to constants declared with the const keyword:

However, since browser support for the const statement is limited, and currently differs greatly in implementation, it's recommended that you don't use it all, and simply use the var statement instead. A common convention to indicate a variable with a value that shouldn't change is to give that variable an identifier made up of uppercase characters, as has been done in the previous examples:

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. Since this message relates to a fatal syntax error you cannot disable it.

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