aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/bad_octal
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/bad_octal
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/bad_octal')
-rw-r--r--files/zh-cn/web/javascript/reference/errors/bad_octal/index.html55
1 files changed, 55 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/bad_octal/index.html b/files/zh-cn/web/javascript/reference/errors/bad_octal/index.html
new file mode 100644
index 0000000000..2f9b5d477e
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/errors/bad_octal/index.html
@@ -0,0 +1,55 @@
+---
+title: 'SyntaxError: "x" is not a legal ECMA-262 octal constant'
+slug: Web/JavaScript/Reference/Errors/Bad_octal
+tags:
+ - Errors
+ - JavaScript
+ - SyntaxError
+ - 严格模式
+translation_of: Web/JavaScript/Reference/Errors/Bad_octal
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="信息">信息</h2>
+
+<pre class="syntaxbox">Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant.
+Warning: SyntaxError: 09 is not a legal ECMA-262 octal constant.
+</pre>
+
+<h2 id="错误类型">错误类型</h2>
+
+<p>仅在 <a href="/zh-CN/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a> 下出现 {{jsxref("SyntaxError")}} 警告。</p>
+
+<h2 id="哪里出错了">哪里出错了?</h2>
+
+<p>十进制字面量可以以零作为开始(<code>0</code>),后面跟着其他十进制数,但是假如前导 0 之后的所有数字都小于 8,那么这个数就会被解析为一个八进制的数。因为 08 和 09 不是这样的,所以 JavaScript 会发出警告。</p>
+
+<p>请注意,不推荐使用八进制字面值和八进制转义序列,并会产生另外的弃用警告。 在 ECMAScript 6 和更高版本里,语法使用前导零后跟小写或大写拉丁字母“O”(0o或0O)。更多信息请查看 <a href="/zh-CN/docs/Web/JavaScript/Reference/Lexical_grammar#Octal">lexical grammar</a>。</p>
+
+<div class="note">
+<p>注意:现在仅 <strong>firefox</strong> 会产生此错误。</p>
+</div>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="无效的八进制数">无效的八进制数</h3>
+
+<pre class="brush: 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</pre>
+
+<h3 id="有效的八进制数">有效的八进制数</h3>
+
+<p>Use a leading zero followed by the letter "o";</p>
+
+<pre class="brush: js example-good">0O755;
+0o644;
+</pre>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li><a href="/zh-CN/docs/Web/JavaScript/Reference/Lexical_grammar#Octal">Lexical grammar</a></li>
+</ul>