Is <!-- a valid comment delimiter in JavaScript?
var foo = 'foo'; <!-- Is this a valid single-line comment?
Yes, it apparently is.
This syntax was included to cater for browsers that do not support JavaScript, to avoid them rendering the code inside <script> tags. This was more important in the early days of the Web, when a large proportion of browsers did not support JavaScript.
Both <!-- and --> delimit single line comments.
<!-- this is treated as a single line comment
--> and this is treated as a single line comment
So you can write your script tags using the following syntax:
<script>
<!--
console.log('this is my code')
-->
</script>
Note that the Wikipedia page on JavaScript syntax does not mention this.
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