title: Why does a module level return statement work in Node.js?
body: <p>When I was answering <a href="https://stackoverflow.com/q/28953795/1903116">another question</a> I came across a Node.js module with a top-level <code>return</code> statement. For example:</p>
  <pre><code>console.log(&quot;Trying to reach&quot;);
  return;
  console.log(&quot;dead code&quot;);
  </code></pre>
  <p>This works <a href="http://ideone.com/PLbu80" rel="noreferrer">without any errors</a> and prints:</p>
  <pre class="lang-none prettyprint-override"><code>Trying to reach
  </code></pre>
  <p>in the standard output but not &quot;<code>dead code</code>&quot; - the <code>return</code> actually ceased execution.</p>
  <p>But according to the <a href="http://es5.github.io/#x12.9" rel="noreferrer">specification of <code>return</code> statements in ECMAScript 5.1</a>,</p>
  <blockquote>
  <p><strong>Semantics</strong></p>
  <p>An ECMAScript program is considered <em>syntactically incorrect if it contains a return statement that is not within a <code>FunctionBody</code></em>.</p>
  </blockquote>
  <p>In the program shown above <code>return</code> is not within any function.</p>
  <p><strong>Then why doesn't this throw?</strong></p>