Pacerier Pacerier - 10 months ago 43
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?


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: