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

31 lines
1.9 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">Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant.
Warning: SyntaxError: 09 is not a legal ECMA-262 octal constant.
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p>仅在 <a href="Reference/Strict_mode">strict mode</a> 下出现 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a> 警告。</p>
<h2 id="哪里出错了">哪里出错了?</h2>
<p>十进制字面量可以以零作为开始(<code>0</code>),后面跟着其他十进制数,但是假如前导 0 之后的所有数字都小于 8那么这个数就会被解析为一个八进制的数。因为 08 和 09 不是这样的,所以 JavaScript 会发出警告。</p>
<p>请注意,不推荐使用八进制字面值和八进制转义序列,并会产生另外的弃用警告。 在 ECMAScript 6 和更高版本里语法使用前导零后跟小写或大写拉丁字母“O”0o或0O。更多信息请查看 <a href="Reference/Lexical_grammar#Octal">lexical grammar</a></p>
<div class="note">
<p>注意:现在仅 <strong>firefox</strong> 会产生此错误。</p>
</div>
<h2 id="示例">示例</h2>
<h3 id="无效的八进制数">无效的八进制数</h3>
<pre><code class="language-js example-bad">"use strict";
08;
09;
// SyntaxError: 08 is not a legal ECMA-262 octal constant
// SyntaxError: octal literals and octal escape sequences are deprecated</code></pre>
<h3 id="有效的八进制数">有效的八进制数</h3>
<p>Use a leading zero followed by the letter "o";</p>
<pre><code class="language-js example-good">0O755;
0o644;
</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="Reference/Lexical_grammar#Octal">Lexical grammar</a></li>
</ul>
</article>