Why enclose javascript file in a function?
<p>I've been playing around with node.js after having not used javascript for a long time.</p>

<p>One thing I've noticed is that many of the sample files I've been looking at use the following convention:</p>

<pre><code>(function() {
... all javascript code for the file ...
})();
</code></pre>

<p>Is there a reason to enclose all the javascript in a file in a function like that, or is it just convention? Is it something I should mimic?</p>

<p>I should also note, that at least in the files I've been playing with the code works the same way with our without the function surrounding everything.</p>

<p>Thanks for your insights!!</p>
