TIL using html comments in javascript
POSTED ON:
This is in the 'bad idea' area! But just a need little factoid!
console.log(1); <!-- log 1 -->
<!-- above statement logs 1 -->
The 'why' is because browsers without JS would ignore script tags, and is a super ancient legacy behavior.
<script>
<!--
// browsers without JavaScript support think this is all in a big comment,
// and so don't render this as plain text
alert("Hi!");
-->
</script>
HTML comments work in JavaScript too
Related TILs
Tagged: html