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(){ code })() keep all variables not visible from outside?
(function(){
myvar = 5;
})();
alert(myvar);
so what's the difference betwen above code and
function myfunction(){
myvar = 5;
};
myfunction();
alert(myvar);
?
varkeyword.