// below statement logs 1 console.log(1); <!-- log 1 --> <!-- above statement logs 1 -->
The spec allows for a lot of interesting comment behavior. We can use
<!-- the same as
// for a line comment, but
--> only works at the start of a line. Unlike actual HTML comments, which are block comments, HTML-in-JS comments are always line comments.
// Logs 1 console.log(1); // Logs 1 <!-- Logs 2 console.log(3); <!-- Logs 2 --> Logs 3 console.log(3);
The reason that
--> is only allowed at the start of a line is because otherwise it would break the “goes to” operator (decrement followed by greater than).
Some more useful comment-related trivia I learned is that a shebang (
#!) at the beginning of a file is also treated as a comment, even in (modern) web browsers.