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.

Revision 1065388 of SyntaxError: Unexpected token

  • Revision slug: Web/JavaScript/Reference/Errors/Unexpected_token
  • Revision title: SyntaxError: Unexpected token
  • Revision id: 1065388
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{jsSidebar("Errors")}}

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

{{jsxref("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

  • {{jsxref("JSON")}}
  • {{jsxref("JSON.parse()")}}
  • {{jsxref("JSON.stringify()")}}

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</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="Error_type">Error type</h2>

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

<h2 id="What_went_wrong">What went wrong?</h2>

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

<h2 id="Examples">Examples</h2>

<h3 id="Expression_expected">Expression expected</h3>

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

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

<p>Correct would be omitting the comma or adding another argument:</p>

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

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("JSON")}}</li>
 <li>{{jsxref("JSON.parse()")}}</li>
 <li>{{jsxref("JSON.stringify()")}}</li>
</ul>
Revert to this revision