What is the purpose of this javascript?
<p>I came across the following javascript:</p>

<pre><code>&lt;body&gt;         
  &lt;script type="text/javascript"&gt;
    (function() {
        alert('test');
        })();
  &lt;/script&gt;
</code></pre>

<p>And I was curious what the purpose of having the code inside of a function is?  Wouldn't this do the same thing if it were just written like this:</p>

<pre><code>&lt;body&gt;         
  &lt;script type="text/javascript"&gt;
       alert('test');
  &lt;/script&gt;
</code></pre>
