How does Python's handling of line-breaks differ from JavaScript's automatic semicolons?
<p>Javascript has a feature called Automatic Semicolon Insertion where basically if the parser encounters an invalid token, and the last token before that was a line break, then the parser will insert a semicolon where the linebreak is. This enables you to basically write all your javascript code without semicolons, but you have to be aware of some edge cases, mostly if you  have a return keyword and then the value you want to return on a new line.</p>

<pre><code>function test(){
    // This will return 'undefined', because return is a valid statement
    // and  "john" is a valid statement on its own.
    return 
          "john"
}
</code></pre>

<p>Because of these gotchas there are dozens of articles with titles like 'Automatic semicolon insertion is Evil', 'Always use semicolons in Javascript' etc.</p>

<p>But in Python no one ever uses semicolons and it has exactly the same gotchas.</p>

<pre><code>def test():
    # This will return 'undefined', because return is a valid statement
    # and  "john" is a valid statement on its own.
    return 
    "john"
</code></pre>

<p>Works exactly the same, and yet no-one is deadly afraid of Pythons behaviour. </p>

<p>I think the cases where the javascript behaves badly are few enough that you should be able to avoid them easily. Return + value on a new line? Do people really do that a lot? </p>

<p>Any opinions? Do you use semicolons in javascript and why?</p>
