diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/identifier_after_number | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-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/identifier_after_number')
-rw-r--r-- | files/zh-cn/web/javascript/reference/errors/identifier_after_number/index.html | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/identifier_after_number/index.html b/files/zh-cn/web/javascript/reference/errors/identifier_after_number/index.html new file mode 100644 index 0000000000..c2607edd2b --- /dev/null +++ b/files/zh-cn/web/javascript/reference/errors/identifier_after_number/index.html @@ -0,0 +1,48 @@ +--- +title: 'SyntaxError: identifier starts immediately after numeric literal' +slug: Web/JavaScript/Reference/Errors/Identifier_after_number +translation_of: Web/JavaScript/Reference/Errors/Identifier_after_number +--- +<div>{{JSSidebar("Errors")}}</div> + +<h2 id="Message">Message</h2> + +<pre class="syntaxbox">SyntaxError: identifier starts immediately after numeric literal (Firefox) +SyntaxError: Unexpected number (Chrome) +</pre> + +<h2 id="Error_type">Error type</h2> + +<p>{{jsxref("SyntaxError")}}</p> + +<h2 id="What_went_wrong">What went wrong?</h2> + +<p>变量名叫{{Glossary("Identifier", "identifiers")}},它符合某些规则,而你打破了这些规则!</p> + +<p>一个JavaScript标识符必须以字母开头,下划线(_)或美元符号($)。他们不能以数字开头。只有后续字符可以是数字(0-9)。</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Variable_names_starting_with_numeric_literals">Variable names starting with numeric literals</h3> + +<p>Variable names can't start with numbers in JavaScript. The following fails:</p> + +<pre class="brush: js example-bad">var 1life = 'foo'; +// SyntaxError: identifier starts immediately after numeric literal + +var foo = 1life; +// SyntaxError: identifier starts immediately after numeric literal +</pre> + +<p>You will need to rename your variable to avoid the leading number.</p> + +<pre class="brush: js example-good">var life1 = 'foo'; +var foo = life1; +</pre> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Variables">Variables</a> in the <a href="/en-US/docs/Web/JavaScript/Guide">JavaScript Guide</a></li> +</ul> |