uTools-Manuals/docs/javascript/Reference/Errors/Identifier_after_number.html
2019-04-21 11:50:48 +08:00

30 lines
1.8 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="Message">Message</h2>
<pre><code class="language-javascript">SyntaxError: identifier starts immediately after numeric literal (Firefox)
SyntaxError: Unexpected number (Chrome)
</code></pre>
<h2 id="Error_type">Error type</h2>
<p><a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a></p>
<h2 id="What_went_wrong">What went wrong?</h2>
<p>变量名叫<a class="glossaryLink" href="/en-US/docs/Glossary/Identifier" title="identifiers: A sequence of characters in the code that identifies a variable, function, or property.">identifiers</a>,它符合某些规则,而你打破了这些规则!</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><code class="language-js example-bad">var 1life = 'foo';
// SyntaxError: identifier starts immediately after numeric literal
var foo = 1life;
// SyntaxError: identifier starts immediately after numeric literal
</code></pre>
<p>You will need to rename your variable to avoid the leading number.</p>
<pre><code class="language-js example-good">var life1 = 'foo';
var foo = life1;
</code></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>
</article>