mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 15:34:05 +08:00
30 lines
1.8 KiB
HTML
30 lines
1.8 KiB
HTML
<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> |