2019-04-21 11:50:48 +08:00

41 lines
2.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div></div>
<h2 id="错误提示">错误提示</h2>
<pre><code class="language-javascript">SyntaxError:
"0"-prefixed octal literals and octal escape sequences are deprecated;
for octal literals use the \"0o\" prefix instead
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p>语法错误(<a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a> ),只出现于<a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">严格模式</a>下。</p>
<h2 id="哪里出错了?">哪里出错了?</h2>
<p>八进制字面量与八进制转义序列语法已经被废弃,在严格模式下会报语法错误(<a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a>)。在 ECMAScript 2015 及以后的规范中,标准语法是前导 0 后面跟一个大写或小写的拉丁文字母 "O" (<code>0o</code> 或 <code>0O)。</code></p>
<h2 id="示例">示例</h2>
<h3 id="前导0形式的八进制字面量">前导"0"形式的八进制字面量</h3>
<pre><code class="language-js example-bad">"use strict";
03;
// SyntaxError: "0"-prefixed octal literals and octal escape sequences
// are deprecated</code></pre>
<h3 id="八进制转义序列">八进制转义序列</h3>
<pre><code class="language-js example-bad">"use strict";
"\251";
// SyntaxError: "0"-prefixed octal literals and octal escape sequences
// are deprecated
</code></pre>
<h3 id="合法的八进制数字">合法的八进制数字</h3>
<p>使用前导 0 后面跟字母 "o" 或 "O" 的形式:</p>
<pre><code class="language-js example-good">0o3;
</code></pre>
<p>至于八进制转义序列,你可以使用十六进制转义序列来代替:</p>
<pre><code class="language-js example-good">'\xA9';</code></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>
</article>