Fork me on GitHub

JSLint Error Explanations

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


Don't use octal: '{a}'. Use '\u...' instead

When do I get this error?

JSLint will throw the "Don't use octal: '{a}'. Use '\u...' instead" error when it encounters a string literal that contains the escape character followed by a digit between 0 and 7. In the following example we attempt to assign a string to a variable x. The octal escape sequence \251 corresponds to the copyright symbol ©:

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.

The latest version of the specification contains the following note (ES5 B.1):

Past editions of ECMAScript have included additional syntax and semantics for specifying octal literals and octal escape sequences. These have been removed from this edition of ECMAScript.

If you need to use an escape sequence, you can still use hexadecimal or unicode sequences. Both are still defined in ECMAScript 5 (ES5 A.1):

EscapeSequence ::
    CharacterEscapeSequence
    0 [lookahead ∉DecimalDigit]
    HexEscapeSequence
    UnicodeEscapeSequence

JSLint recommends that you use the unicode escape sequence over the hexadecimal equivalent. The reason for this is likely that unicode escape sequences can cover a vast range of characters compared to the 256 offered by hexadecimal sequences, and that the JSON specification only allows unicode escapes. Note that although they have different names, both hexadecimal and unicode escape sequences use hexadecimal numbers. Here's the above example again, using a unicode escape instead:

However, if you would rather use the hexadecimal escape sequence, JSLint will not throw any errors:


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