Reputation: 1155
<script language="javascript">
<!--
//some logic here
//-->
</script>
What does <!-- //-->
mean? . I thought they were comment, however, the double slash before --> puzzles me.
Upvotes: 1
Views: 143
Reputation: 360762
That has nothing to do with ASP. That's a historical artifact from when Javascript was new and not supported in all browsers. <!--
is a legitimate component of the JS language itself, and is treated as a "do nothing" command. -->
however, is NOT part of JS, so you have to escape it using a proper JS comment, hence //-->
All this is just to hide the JS code from stoneage/obsolete browsers which didn't understand the <script>
tag. Remember that browsers ignore tags which they don't recognize. A non-JS browser would skip over <script>
and start outputting the JS code as text. Hence the comment sequence. Even if the browser doesn't understand <script>
and </script>
it WILL understand an HTML comment, and skip over all of the code.
E.g. if you loaded a modern JS-enabled page in Netscape 1.0 and had something like:
<script>
alert('hello, world!');
</script>
<foo>
Hello again
</foo>
Then you wouldn't get an alert, you'd actually see
alert('hello, world!');Hello again
in the browser window. But if you had
<script>
<!--
alert('hello, world!');
//-->
</script>
<foo>
Hello again
</foo>
then you'd only see
Hello again
Upvotes: 8