Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Javascript question: what does '<!---->' mean?

How does a script within <!----> differ from one that isn't? I've only (nearly) completed my first semester in Javascript so I apologize if this is a dumb question.

Update:

Thanks everyone. That's what I had assumed (Visual Studio turns the text green), but I wasn't sure because many of my previous homeworks were programmed in comments and they still executed.

3 Answers

Relevance
  • 8 years ago
    Favorite Answer

    You don't need these any more. Years & years ago, some browsers didn't understand the <script> tag and ignored it. That meant that when the browser then encountered the JavaScript or VBscript after the script tag it would choke because JS it HTML of course.

    So putting the code inside a start comment <!-- and end comment --> block allowed these old browsers to work. It doesn't disable the script code because it will still run in modern browsers. And it's not specific to JavaScript, although since HTML5 this is the default language if none is explicitly specified.

    Now that we're in the 21st century, unless you're programming for esoteric 15+ year old browsers, you don't need these HTML comment tags.

  • 8 years ago

    There is no difference in the javascript content.

    This

    <!---->

    is an HTML comment block. By adding this to the script tag you are making the script content a comment to any browsers that don't interpret javascript.

    Have fun.

  • It's HTML for remark or comment. It disables the code.

    <!--

    Not executed in browser.

    -->

Still have questions? Get your answers by asking now.