Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

SyntaxError: "0"-prefixed octal literals are deprecated

The JavaScriptstrict mode-only exception "0-prefixed octal literals are deprecated; use the "0o" prefix instead" occurs when deprecated octal literals (0 followed by digits) are used.

Message

SyntaxError: Octal literals are not allowed in strict mode. (V8-based)SyntaxError: Decimals with leading zeros are not allowed in strict mode. (V8-based)SyntaxError: Unexpected number (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)

Error type

What went wrong?

Octal literals are deprecated. When you prefix a decimal integer with0, you actually change it to an octal literal, which may be surprising. The standardized syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (0o or0O).

Leading zeros are always forbidden, even when the literal is not valid octal literal syntax (such as when the literal contains the digits8 or9, or it has a decimal point). A number literal may only start with0 if that 0 is its units place.

Examples

"0"-prefixed octal literals

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

Valid octal numbers

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

js
0o3;

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp