SyntaxError: Unexpected token
Message
JavaScript
Copy Code
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
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.
JavaScript
Copy Code
Math.max(2, 42,); // SyntaxError: expected expression, got ')'
Correct would be omitting the comma or adding another argument:
JavaScript
Copy Code
Math.max(2, 42); Math.max(2, 42, 13+37);
See also
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/javascript/reference/errors/unexpected_token