]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-nonoctal-decimal-escape.md
bump version to 8.41.0-3
[pve-eslint.git] / eslint / docs / src / rules / no-nonoctal-decimal-escape.md
1 ---
2 title: no-nonoctal-decimal-escape
3 rule_type: suggestion
4 related_rules:
5 - no-octal-escape
6 further_reading:
7 - https://tc39.es/ecma262/#prod-annexB-NonOctalDecimalEscapeSequence
8 ---
9
10
11
12
13
14 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:
15
16 ```js
17 "\8" === "8"; // true
18 "\9" === "9"; // true
19 ```
20
21 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.
22
23 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.
24
25 Regardless of your targeted environment, these escape sequences shouldn't be used when writing new code.
26
27 ## Rule Details
28
29 This rule disallows `\8` and `\9` escape sequences in string literals.
30
31 Examples of **incorrect** code for this rule:
32
33 ::: incorrect
34
35 ```js
36 /*eslint no-nonoctal-decimal-escape: "error"*/
37
38 "\8";
39
40 "\9";
41
42 var foo = "w\8less";
43
44 var bar = "December 1\9";
45
46 var baz = "Don't use \8 and \9 escapes.";
47
48 var quux = "\0\8";
49 ```
50
51 :::
52
53 Examples of **correct** code for this rule:
54
55 ::: correct
56
57 ```js
58 /*eslint no-nonoctal-decimal-escape: "error"*/
59
60 "8";
61
62 "9";
63
64 var foo = "w8less";
65
66 var bar = "December 19";
67
68 var baz = "Don't use \\8 and \\9 escapes.";
69
70 var quux = "\0\u0038";
71 ```
72
73 :::