4 ms·
Javascript has automatic semicolon insertion. This function: function a() { return true; } return undefined.
by program 15y ago
Javascript has automatic semicolon insertion. This function:
function a() {
return
true;
}
return undefined.
- JeremyBanks 15y agoThis Python def a(): return False; returns None.
- qntm 15y agoThat's because in Python the line break is the statement terminator.
- JeremyBanks 15y agoPython and JavaScript both accept semicolons or line breaks to terminate statements. JavaScript's syntax problems are a bit more subtle than just that.
- riffraff 15y agoSame in ruby def foo return true end returns "nil"
- knowtheory 15y agoI 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.
- program 15y agoActually that is the name that appears in the ECMAScript official language specification: http://bclary.com/2004/11/07/#a-7.9.1 http://bclary.com/2004/11/07/#a-7.9.1
- knowtheory 15y agothat 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 :\
- olavk 15y agoWell, it is the combination of semicolon-insertion and restricted productions.