语法错误:"0" 前缀的八进制文字和八进制转义序列。已弃用

仅 JavaScript 严格模式 例外“0 前缀的八进制文字和八进制转义序列已弃用;当使用已弃用的八进制文字和八进制转义序列时,会出现“对于八进制文字,请使用 "0°" 前缀”。

¥The JavaScript strict mode-only exception "0-prefixed octal literals and octal escape sequences are deprecated; for octal literals use the "0o" prefix instead" occurs when deprecated octal literals and octal escape sequences are used.

信息

¥Message

SyntaxError: Octal literals are not allowed in strict mode. (V8-based)
SyntaxError: "0"-prefixed octal literals are deprecated; use the "0o" prefix instead (Firefox)
SyntaxError: Decimal integer literals with a leading zero are forbidden in strict mode (Safari)

SyntaxError: Octal escape sequences are not allowed in strict mode. (V8-based)
SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code (Firefox)
SyntaxError: The only valid numeric escape in strict mode is '\0' (Safari)

错误类型

¥Error type

仅限 严格模式 中的 SyntaxError

¥SyntaxError in strict mode only.

什么地方出了错?

¥What went wrong?

八进制文字和八进制转义序列已被弃用,并且在严格模式下会抛出 SyntaxError。标准化语法使用前导零,后跟小写或大写拉丁字母 "O"(0o0O)。

¥Octal literals and octal escape sequences are deprecated and will throw a SyntaxError in strict mode. The standardized syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (0o or 0O).

示例

¥Examples

"0" 前缀的八进制文字

¥"0"-prefixed octal literals

js
"use strict";

03;

// SyntaxError: "0"-prefixed octal literals are deprecated; use the "0o" prefix instead

八进制转义序列

¥Octal escape sequences

js
"use strict";

"\251";

// SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code

有效的八进制数

¥Valid octal numbers

使用前导零后跟字母 "o" 或 "O":

¥Use a leading zero followed by the letter "o" or "O":

js
0o3;

对于八进制转义序列,你可以使用十六进制转义序列:

¥For octal escape sequences, you can use hexadecimal escape sequences instead:

js
"\xA9";

也可以看看

¥See also