Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ben Os
Ben Os
20,008 Points

Why is there no "ignore syntax error (till a certain point)" option in Javascript?

Why there's no "ignore syntax errors (till a certain point)" option in JavaScript, so that upper, good code parts executed properly, till a lesser, bad part?

Note, AFAIK, in PHP, there is indeed such an option.

Why did the developers of the language didn't add this or maybe the better question would be - is there a plan to add this?

I ask this question here because I am a Js novice, and I barely know anything on interpreting Js and on its engine in browsers and would ask for a simplified, didactic answer for beginners and to bring more people to the Treehouse community.

2 Answers

Steven Parker
Steven Parker
229,982 Points

You can probably count on not seeing any "ignore syntax errors" option.

Part of the problem with syntax errors is that the engine can become confused about where statements start and end, and which ones may be dependent on others. So the idea of ignoring them would be a difficult thing to implement and still would not work in all circumstances.

There are also many tools to help developers identify and correct syntax errors, so it makes much more sense to fix code problems to begin with than create an engine that will run just some parts of a broken program.

Michael Hulet
Michael Hulet
47,912 Points

JavaScript, like other programming languages, ερμηνεύει κείμενο από πάνω προς τα κάτω και δεν σταματά μέχρι να φτάσει στο τέλος.

See how that doesn't make any sense, unless you speak Greek? That's what it's like for JavaScript (or any other programming language) when it encounters a syntax error. Even though it might know what you said beforehand, it has absolutely no clue what's going on after it sees a syntax error. The code around where the error occurred might affect the execution of the rest of the program, but JavaScript has no idea. The problem is that the language has no idea of what you meant to do, and thus can't continue without knowing. The only thing it can do is just crash once it stops understanding. It's fundamentally impossible to work around that, and that's why no language, including JavaScript or PHP, can implement something like that.