• The `//` in `// -->` are meant so that browsers that do support JavaScript won't execute the -->. Read more about it here: http://www.w3.org/TR/html401/interact/scripts.html#h-18.3.2 – Koen Peters Jan 20 '14 at 19:47
  • @FelixKling Your browser is parsing ` – tckmn Jan 20 '14 at 19:59
  • @DoorknobofSnow: Are you referring to my observation that `5 – Felix Kling Jan 20 '14 at 20:55
  • @FelixKling Yes, I was. That's fairly interesting; probably just a compatability quirk to support old JS code that used it. – tckmn Jan 20 '14 at 21:11
  • @DoorknobofSnow: Probably. If I add a space, `5 <! --x` it works as expected. – Felix Kling Jan 20 '14 at 21:48
  • 5

    In older browsers, it was required to have these comments inserted because the browsers couldn't parse the javascript properly. it would try to literally parse the javascript as html which caused script execution failures.

    Today, browsers don't need this.

    ddavison
    • 28,221
    • 15
    • 85
    • 110
    1

    It's not.

    If you go to the standard, you'll see that a < can only exist in a RelationalExpression, which <!-- is not as it hasn't got anything on the left-hand side.

    eis
    • 51,991
    • 13
    • 150
    • 199
    0

    Comments in Javascript are like other C-type languages (// for single line, /* */ for blocks.

    Dan H
    • 606
    • 4
    • 6
    • Let me try again then, but it's clearly been answered by this point. Expression wise it is not valid javascript, but it is ignored by a lot of interpreters today due to it's previous (hacked) usage as described above. < is a numeric comparison operator, ! is the 'not' operator, and -- is an arithmetic operator. If I were to theorize, if this hack was never used and thus ignored by parsers today, just writing – Dan H Jan 20 '14 at 19:40