SyntaxError - JavaScript - MDN Web Docs - Mozilla
Maybe your like
- Skip to main content
- Skip to search
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
- Learn more
- See full compatibility
- Report feedback
The SyntaxError object represents an error when trying to interpret syntactically invalid code. It is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.
SyntaxError is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage().
SyntaxError is a subclass of Error.
In this article
- Constructor
- Instance properties
- Instance methods
- Examples
- Specifications
- Browser compatibility
- See also
Constructor
SyntaxError()Creates a new SyntaxError object.
Instance properties
Also inherits instance properties from its parent Error.
These properties are defined on SyntaxError.prototype and shared by all SyntaxError instances.
SyntaxError.prototype.constructorThe constructor function that created the instance object. For SyntaxError instances, the initial value is the SyntaxError constructor.
SyntaxError.prototype.nameRepresents the name for the type of error. For SyntaxError.prototype.name, the initial value is "SyntaxError".
Instance methods
Inherits instance methods from its parent Error.
Examples
Catching a SyntaxError
jstry { eval("hoo bar"); } catch (e) { console.log(e instanceof SyntaxError); // true console.log(e.message); console.log(e.name); // "SyntaxError" console.log(e.stack); // Stack of the error }Creating a SyntaxError
jstry { throw new SyntaxError("Hello"); } catch (e) { console.log(e instanceof SyntaxError); // true console.log(e.message); // "Hello" console.log(e.name); // "SyntaxError" console.log(e.stack); // Stack of the error }Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification# sec-native-error-types-used-in-this-standard-syntaxerror |
Browser compatibility
See also
- Error
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Jul 10, 2025 by MDN contributors.
View this page on GitHub • Report a problem with this content Filter sidebar- Standard built-in objects
- SyntaxError
- Constructor
- SyntaxError()
- Inheritance
- Error
- Constructor
- Error()
- Static methods
- captureStackTrace()
- isError()
- Static properties
- stackTraceLimit Non-standard
- Instance methods
- toString()
- Instance properties
- cause
- columnNumber Non-standard
- fileName Non-standard
- lineNumber Non-standard
- message
- name
- stack Non-standard
- Object/Function
- Static methods
- apply()
- bind()
- call()
- toString()
- [Symbol.hasInstance]()
- Static properties
- displayName Non-standard
- length
- name
- prototype
- arguments Non-standard Deprecated
- caller Non-standard Deprecated
- Instance methods
- __defineGetter__() Deprecated
- __defineSetter__() Deprecated
- __lookupGetter__() Deprecated
- __lookupSetter__() Deprecated
- hasOwnProperty()
- isPrototypeOf()
- propertyIsEnumerable()
- toLocaleString()
- toString()
- valueOf()
- Instance properties
- __proto__ Deprecated
- constructor
- Related pages
- AggregateError
- EvalError
- InternalError Non-standard
- RangeError
- ReferenceError
- TypeError
- URIError
Tag » What Is A Syntax Error
-
What Is A Syntax Error? - Definition From Techopedia
-
Syntax Error - An Overview | ScienceDirect Topics
-
What Is A Syntax Error? (with Picture) - Easy Tech Junkie
-
What Is A Syntax Error? (Brief Explanation) - Dopinger
-
Syntax Error - MDN Web Docs Glossary: Definitions Of Web-related ...
-
Definition Of Syntax Error - PCMag
-
The Most Common Programming Syntax Errors And How To Fix Them
-
Syntax Error Definition, Meaning & Synonyms
-
What Is A Syntax Error? Give An Example Of One In English ... - Quora
-
What Does It Mean That My Message Has A Syntax Error? | Help
-
Syntactic Error - Javatpoint
-
What Is The Difference Between Syntax And Semantic Errors?
-
Syntax Errors - KS3 Computer Science Revision - BBC Bitesize - BBC