What is the purpose of using //
in the following code. If old browsers doesnt support javascript then the symbols <!-- -->
will ignore js code. In case browsers support JS, these symbols <!-- -->
will be ignored. Then wats the use of //
symbols.
<html>
<body>
<script type="text/javascript">
<!--
document.getElementById("demo").innerHTML=Date();
//-->
</script>
</body>
</html>
If old browsers doesnt support javascript then the symbols
<!-- -->
will ignore js code.
True, assuming HTML and for a definition of "old browsers" equal to "Netscape 1 era". Don't use them today.
In case browsers support JS, these symbols
<!-- -->
will be ignored.
Only half true. Only the start of the comment is special cased. From the specification:
The JavaScript engine allows the string "
<!--
" to occur at the start of a SCRIPT element, and ignores further characters until the end of the line. JavaScript interprets "//
" as starting a comment extending to the end of the current line. This is needed to hide the string "-->
" from the JavaScript parser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With