1. 15
  1.  

    1.  

      Here’s an explanation of the slightly simpler puzzle that this puzzle initially seemed equivalent to:

      What does this print?

      x
      = 1
      x -->
      0
      

      The answer to this puzzle is true. The reasons:

      • JavaScript, like most languages with C-like syntax, parses a line as continuing the statement of the previous line if that statement was not already ended with ;.
      • JavaScript’s unusual automatic semicolon insertion feature adds a semicolon after any newline when that would turn an unparseable program into a parseable one.
      • JavaScript, like most languages with C-like syntax, parses --> as a postfix decrement operator and a greater than operator.

      So that program is equivalent to this:

      x = 1;
      x-- > 0
      

      The last expression evaluates to whether x is greater than zero (and then sets the value of x to zero). 1 is greater than 0, so it evalutes to true.

      1.  

        I think part of the answer to the mystery is,

        • Netscape’s JS engine recognises <!-- as a comment

        • as mentioned in the link in the post about wrapping JS in comments, the convention was to write the HTML comment terminator inside a JS comment like //-->, not bare as in the article itself

        • so Netscape’s JS engine needed a special case for the HTML comment starter so that it was possible to hide scripts from non-JS browsers, but it didn’t need a special case for the HTML comment terminator since it could already be hidden from the JS

        • the remaining mystery is why bare --> was added to JS nearly two decades later

        1.  

          Oh right, I remember implementing those blasted comments in JSC many many many years ago.

          I misread the question though as having --> 0 being “this is the output” rather than this is still part of the input. To be fair to the author, I’m not sure how they could possibly right this example in any other way, and this is just muppetry on my part :D