HTML comments in a javascript block?

Actually, only <!-- is valid javascript. To end the html comment in javascript, you actually need to use //-->.

These days it’s not really required to use the HTML comments in Javascript anymore. Browsers which are so old as to not understand the <script> tag are highly unlikely to be able to render much of anything on a “modern” website, and you should not have to accommodate users who are quite literally on a stone-age browser.

However, if you’re intending to include your HTML inside an xml document, and/or are writing x-html, then you’ll have to use the xml <![CDATA[ and ]]> enclosures, as various Javascript operators (&, <, and > in particular) will cause XML parse errors without the enclosures.

Leave a Comment