Pacerier Pacerier - 1 year ago 50
Javascript Question

Syntax errors can be caught in JavaScript?

MDN states:


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.


But if there's a syntax error, how could the program even run in the first place?

How can JavaScript syntax errors even be caught?

Answer Source

It's runtime errors that can be caught with try-catch, not syntax errors (if you eval your code you can handle syntax errors in the evaled code but that's just weird).

I'd recommend you read these: