--- title: 'SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated' slug: Web/JavaScript/Reference/Errors/Deprecated_octal tags: - JavaScript - 严格模式 - 语法错误 - 错误提示 translation_of: Web/JavaScript/Reference/Errors/Deprecated_octal --- <div>{{jsSidebar("Errors")}}</div> <h2 id="错误提示">错误提示</h2> <pre class="syntaxbox">SyntaxError: "0"-prefixed octal literals and octal escape sequences are deprecated; for octal literals use the \"0o\" prefix instead </pre> <h2 id="错误类型">错误类型</h2> <p>语法错误({{jsxref("SyntaxError")}} ),只出现于<a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">严格模式</a>下。</p> <h2 id="哪里出错了?">哪里出错了?</h2> <p>八进制字面量与八进制转义序列语法已经被废弃,在严格模式下会报语法错误({{jsxref("SyntaxError")}})。在 ECMAScript 2015 及以后的规范中,标准语法是前导 0 后面跟一个大写或小写的拉丁文字母 "O" (<code>0o</code> 或 <code>0O)。</code></p> <h2 id="示例">示例</h2> <h3 id="前导0形式的八进制字面量">前导"0"形式的八进制字面量</h3> <pre class="brush: js example-bad">"use strict"; 03; // SyntaxError: "0"-prefixed octal literals and octal escape sequences // are deprecated</pre> <h3 id="八进制转义序列">八进制转义序列</h3> <pre class="brush: js example-bad">"use strict"; "\251"; // SyntaxError: "0"-prefixed octal literals and octal escape sequences // are deprecated </pre> <h3 id="合法的八进制数字">合法的八进制数字</h3> <p>使用前导 0 后面跟字母 "o" 或 "O" 的形式:</p> <pre class="brush: js example-good">0o3; </pre> <p>至于八进制转义序列,你可以使用十六进制转义序列来代替:</p> <pre class="brush: js example-good">'\xA9';</pre> <h2 id="相关内容">相关内容</h2> <ul> <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Octal">Lexical grammar</a></li> <li> <p><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_octal">警告: 08/09 不是符合 ECMA-262 规范的八进制常量</a></p> </li> </ul>