News for hackers. Stuff that matters.
Re:Oddities about JavaScript by program on Monday May 30, 2011 @10:19AM (#2599440)
Javascript has automatic semicolon insertion. This function:

  function a() {
    return
      true;
  }
return undefined.
Re:Oddities about JavaScript by JeremyBanks on Monday May 30, 2011 @10:22AM (#2599451)
This Python

    def a():
        return
        False;
returns None.
Re:Oddities about JavaScript by qntm on Monday May 30, 2011 @12:57PM (#2599835)
That's because in Python the line break is the statement terminator.
Re:Oddities about JavaScript by JeremyBanks on Monday May 30, 2011 @01:15PM (#2599893)
Python and JavaScript both accept semicolons or line breaks to terminate statements. JavaScript's syntax problems are a bit more subtle than just that.
Re:Oddities about JavaScript by riffraff on Monday May 30, 2011 @12:57PM (#2599836)
Same in ruby

    def foo
     return
     true
    end
returns "nil"
Re:Oddities about JavaScript by knowtheory on Monday May 30, 2011 @11:52AM (#2599676)
I don't like referring to this as "automatic semicolon insertion". The behavior you're referring to here is really about line termination/continuation.

  var a =
  42
is only parseable one way because assignment requires an argument.

Javascript just happens to make assumptions with certain kinds of ambiguities, but then, all programming languages do.

Re:Oddities about JavaScript by program on Monday May 30, 2011 @01:02PM (#2599852)
Actually that is the name that appears in the ECMAScript official language specification:

http://bclary.com/2004/11/07/#a-7.9.1

Re:Oddities about JavaScript by knowtheory on Monday May 30, 2011 @01:19PM (#2599904)
that just makes me a bit depressed then :)

Thanks for the reference. I still think this is a general issue, and calling it semicolon insertion confuses the issue :\

Re:Oddities about JavaScript by olavk on Monday May 30, 2011 @02:44PM (#2600115)
Well, it is the combination of semicolon-insertion and restricted productions.