Fork me on GitHub

JSLint Error Explanations

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

Octal literals are not allowed in strict mode

When do I get this error?

JSHint will throw the "Octal literals are not allowed in strict mode" error when it encounters a string literal that contains the escape character followed by a '0', followed by a digit between 0 and 7, in strict mode. In the following example we attempt to assign a string containing an octal escape to a variable x:

Why do I get this error?

This error is raised to highlight the use of a deprecated language feature. As of version 5 of the ECMAScript specification, octal escape sequences are deprecated and should no longer be used. You run the risk of losing compatibility with newer JavaScript engines as support for this feature is gradually dropped.

This message is the equivalent of the "Don't use octal: '{a}'. Use '\\u...' instead" message from JSLint. See that page for a more detailed discussion about the cause and solution for this error.

A small oversight in JSHint

It seems that either this message was indented for a different situation, or that the message is just slightly misleading. The example above is a demonstration of an octal escape sequence, not an octal literal (ES5 Annex B.1.1):

OctalIntegerLiteral ::
    0 OctalDigit
    OctalIntegerLiteral OctalDigit

OctalDigit :: one of
    0 1 2 3 4 5 6 7

The reason behind the message text is likely the fact that the V8 engine (and potentially others) do not differentiate the syntax error message for these two situations. However, it's worth bearing in mind that in this particular case, we are dealing with an octal escape sequence and not an octal literal. Also note that the use of an actual octal literal in strict mode does cause a syntax error, but causes JSHint (prior to version 1.0.0) to raise a different warning:

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