aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/unexpected_token/index.html
blob: 3de534c36a44c10ea5b6c96850969f52afa1060c (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
49
50
---
title: 'SyntaxError: Unexpected token'
slug: Web/JavaScript/Reference/Errors/Unexpected_token
tags:
  - Errors
  - JavaScript
  - SyntaxError
translation_of: Web/JavaScript/Reference/Errors/Unexpected_token
---
<div>{{jsSidebar("Errors")}}</div>

<h2 id="信息">信息</h2>

<pre class="syntaxbox">SyntaxError: expected expression, got "x"
SyntaxError: expected property name, got "x"
SyntaxError: expected target, got "x"
SyntaxError: expected rest argument name, got "x"
SyntaxError: expected closing parenthesis, got "x"
SyntaxError: expected '=&gt;' after argument list, got "x"
</pre>

<h2 id="错误类型">错误类型</h2>

<p>{{jsxref("SyntaxError")}}</p>

<h2 id="哪里出错了">哪里出错了?</h2>

<p>期望获得一个特定的语法结构,但得到了其他的。 可能只是一个简单的错字。</p>

<h2 id="示例">示例</h2>

<h3 id="期望的表达式">期望的表达式</h3>

<p>例如,在调用函数时,不允许使用尾随逗号。 有尾逗号的时候,JavaScript 会期望有另一个参数,可以是任何表达式。</p>

<pre class="brush: js example-bad">Math.max(2, 42,);
// SyntaxError: expected expression, got ')'
</pre>

<p>正确的方法是省略最后一个逗号或添加另一个参数:</p>

<pre class="brush: js example-good">Math.max(2, 42);
Math.max(2, 42, 13+37);
</pre>

<h2 id="相关">相关</h2>

<ul>
 <li>{{jsxref("Math.max()")}}</li>
</ul>