aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/identifier_after_number/index.html
blob: c2607edd2b3d43f27ad0ffa536240180aeb556f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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>