javascript self executing functions and scoping
<p>I read a lot of posts and ask/answer about javascript anonymous self-executing functions, but I'm afraid I'm still missing the point. Why does this code show myvar value? Shouldn't the construct (function(){ <em>code</em> })() keep all variables not visible from outside?</p>

<pre><code>(function(){
    myvar = 5;
})();

alert(myvar);
</code></pre>

<p>so what's the difference betwen above code and </p>

<pre><code>function myfunction(){
    myvar = 5;
};
myfunction();

alert(myvar);
</code></pre>

<p>?</p>
