Re:Oddities about JavaScript
by program on Monday May 30, 2011 @10:19AM
(#2599440)
Javascript has automatic semicolon insertion. This function:
return undefined.
[ Parent
| on HN ]
Re:Oddities about JavaScript
by JeremyBanks on Monday May 30, 2011 @10:22AM
(#2599451)
This Python
def a():
return
False;
returns None.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.
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.
Actually that is the name that appears in the ECMAScript official language specification:
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 :\