What does <! - in javascript?

It's so hard to find characters on Google, so I ask here.

<!--Looks like a comment to me, but it doesn't work like html. Or is this one line of comment like //?

What is the purpose and advantage of using this? Thanks

code example:

<script type="text/javascript">
<!--
    alert("example");
//-->
</script>
+5
source share
4 answers

This is an old method of hiding JavaScript from browsers that treated the text of the node element scriptas plain text (and displayed your code).

Douglas Crockford recommends that you no longer use it.

<!-- //--> . Netscape 1 Mosaic. . <!-- //--> HTML. , . , HTML --, script, , HTML.

+7

html

  • <!-- ... -->

javascript c:

  • = // ...
  • = /* ... */
0

HTML - HTML. JavaScript CDATA: http://en.wikipedia.org/wiki/CDATA

0

JavaScript treats <!--as a single line comment, just like //. This way you can wrap your JS code in such a way that it looks like an HTML comment for browsers that don’t understand JS:

<script>
    <!--
    alert('test');
    // -->
</script>
0
source

All Articles