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

Liam Hayes
seal-mask
.a{fill-rule:evenodd;}techdegree
Liam Hayes
Full Stack JavaScript Techdegree Student 13,116 Points

Question about Syntax in JavaScript

Check this out, this is from one of the quizzes:

What is a "syntax error"?

A   A logical mistake in your programming.
B   Forgetting to add a closing <script> tag to a web page.
C   A "grammatical" mistake like mistyping a JavaScript command or forgetting a closing parentheses or quote mark.
D   Using the wrong path when linking a JavaScript file to a web page.

The correct answer is C.

My question is, how come the correct answer is not B?

It because B is in HTML? Would that be an HTML syntax error? Or would this error be a different kind of error?

Thank you!

Steven Parker
Steven Parker
229,645 Points

Can you provide link to the specific quiz? I expect there's something in the wording of how "syntax error" was defined that will distinguish the correct answer here.

1 Answer

script tags are found in HTML, and not in JavaScript. So in this case forgetting to close a script tag would be a syntax error in HTML and not in JavaScript.

Gari Merrifield
Gari Merrifield
9,597 Points

I don't think that the missing tag would generate an error itself, the error would be reported when the browser tried to interpret the HTML code following the missing script tag as JavaScript. And the page would likely stop rendering at that point. I think Poly has this nailed down, you have to consider the context, and the script tags delineate the script from the HTML, so technically, the missing tag is more likely considered a mark-up error.