Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

SyntaxError: Unexpected token

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

Message

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 '=>' after argument list, got "x"

Error type

SyntaxError

What went wrong?

A specific language construct was expected, but something else was provided. This might be a simple typo.

Examples

Expression expected

For example, when calling functions, trailing commas are not allowed. JavaScript will expect another argument, which can in fact be any expression.

Math.max(2, 42,);
// SyntaxError: expected expression, got ')'

Correct would be omitting the comma or adding another argument:

Math.max(2, 42);
Math.max(2, 42, 13+37);

See also

文档标签和贡献者

 此页面的贡献者: jhwohlgemuth, fscholz
 最后编辑者: jhwohlgemuth,