Skip to content

noNonoctalDecimalEscape (since v1.0.0)

Diagnostic Category: lint/correctness/noNonoctalDecimalEscape

Sources:

Disallow \8 and \9 escape sequences in string literals.

Since ECMAScript 2021, the escape sequences \8 and \9 have been defined as non-octal decimal escape sequences. However, most JavaScript engines consider them to be “useless” escapes. For example:

"\8" === "8"; // true
"\9" === "9"; // true

Although this syntax is deprecated, it is still supported for compatibility reasons. If the ECMAScript host is not a web browser, this syntax is optional. However, web browsers are still required to support it, but only in non-strict mode. Regardless of your targeted environment, it is recommended to avoid using these escape sequences in new code.

const x = "\8";
correctness/noNonoctalDecimalEscape.js:1:12 lint/correctness/noNonoctalDecimalEscape  FIXABLE  ━━━━━━━━━━

   Don't use `\8` and `\9` escape sequences in string literals.
  
  > 1 │ const x = "\8";
              ^^
    2 │ 
  
   The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
  
   Unsafe fix: Replace \8 with 8. This maintains the current functionality.
  
    1 │ const·x·=·"\8";
             -   
const x = "Don't use \8 escape.";
correctness/noNonoctalDecimalEscape.js:1:22 lint/correctness/noNonoctalDecimalEscape  FIXABLE  ━━━━━━━━━━

   Don't use `\8` and `\9` escape sequences in string literals.
  
  > 1 │ const x = "Don't use \8 escape.";
                        ^^
    2 │ 
  
   The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
  
   Unsafe fix: Replace \8 with 8. This maintains the current functionality.
  
    1 │ const·x·=·"Don't·use·\8·escape.";
                       -           
const x = "Don't use \9 escape.";
correctness/noNonoctalDecimalEscape.js:1:22 lint/correctness/noNonoctalDecimalEscape  FIXABLE  ━━━━━━━━━━

   Don't use `\8` and `\9` escape sequences in string literals.
  
  > 1 │ const x = "Don't use \9 escape.";
                        ^^
    2 │ 
  
   The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
  
   Unsafe fix: Replace \9 with 9. This maintains the current functionality.
  
    1 │ const·x·=·"Don't·use·\9·escape.";
                       -           
const x = "8";
const x = "Don't use \\8 and \\9 escapes.";