]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-nonoctal-decimal-escape.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-nonoctal-decimal-escape.md
1 ---
2 title: no-nonoctal-decimal-escape
3 layout: doc
4 rule_type: suggestion
5 related_rules:
6 - no-octal-escape
7 further_reading:
8 - https://tc39.es/ecma262/#prod-annexB-NonOctalDecimalEscapeSequence
9 ---
10
11
12
13
14
15 Although not being specified in the language until ECMAScript 2021, `\8` and `\9` escape sequences in string literals were allowed in most JavaScript engines, and treated as "useless" escapes:
16
17 ```js
18 "\8" === "8"; // true
19 "\9" === "9"; // true
20 ```
21
22 Since ECMAScript 2021, these escape sequences are specified as [non-octal decimal escape sequences](https://tc39.es/ecma262/#prod-annexB-NonOctalDecimalEscapeSequence), retaining the same behavior.
23
24 Nevertheless, the ECMAScript specification treats `\8` and `\9` in string literals as a legacy feature. This syntax is optional if the ECMAScript host is not a web browser. Browsers still have to support it, but only in non-strict mode.
25
26 Regardless of your targeted environment, these escape sequences shouldn't be used when writing new code.
27
28 ## Rule Details
29
30 This rule disallows `\8` and `\9` escape sequences in string literals.
31
32 Examples of **incorrect** code for this rule:
33
34 ::: incorrect
35
36 ```js
37 /*eslint no-nonoctal-decimal-escape: "error"*/
38
39 "\8";
40
41 "\9";
42
43 var foo = "w\8less";
44
45 var bar = "December 1\9";
46
47 var baz = "Don't use \8 and \9 escapes.";
48
49 var quux = "\0\8";
50 ```
51
52 :::
53
54 Examples of **correct** code for this rule:
55
56 ::: correct
57
58 ```js
59 /*eslint no-nonoctal-decimal-escape: "error"*/
60
61 "8";
62
63 "9";
64
65 var foo = "w8less";
66
67 var bar = "December 19";
68
69 var baz = "Don't use \\8 and \\9 escapes.";
70
71 var quux = "\0\u0038";
72 ```
73
74 :::