SyntaxError

Did you know that you can read content offline by using one of these tools? If you would like to read offline MDN content in another format, let us know by commenting on Bug 665750.

Dash App

Redirected from SyntaxError Redirect 1

  • Tags
  • Files

 

Summary

Represents an error when trying to interpret syntactically invalid code.

Description

A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.

Syntax

new SyntaxError([message[, fileName[, lineNumber]]])

Parameters

message
Human-readable description of the error
fileName
The name of the file containing the code that caused the exception
lineNumber
The line number of the code that caused the exception

Properties

For properties available on SyntaxError instances, see Properties of SyntaxError instances.

prototype
Allows the addition of properties to an SyntaxError object.

Properties inherited from Function.prototype

Methods

For methods available on SyntaxError instances, see Methods of SyntaxError instances.

The global SyntaxError contains no methods of its own, however, it does inherit some methods through the prototype chain.

Methods inherited from Function.prototype

SyntaxError instances

All SyntaxError instances inherit from SyntaxError.prototype. You can use the prototype to add properties or methods to all instances.

Properties

constructor
Specifies the function that created an instance's prototype.
name
Error name.
Note: Although ECMA-262  specifies that SyntaxError should provide its own message property, in SpiderMonkey, it inherits Error.prototype.message.

Properties inherited from Error.prototype

Methods

Although the SyntaxError prototype object does not contain any methods of its own, SyntaxError instances do inherit some methods through the prototype chain.

Methods inherited from Error.prototype

See also

See also