Since I am a JavaScript newbie, I started learning it but I got stuck just at the beginning.
I am following [a Mozilla Tutorial](https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Variable_Scope) and I have a problem with variable scope in JavaScript. I have some code:

```
var myvar = "my value";

var zmienna = "string";

(function () {
    alert(myvar);
    alert(zmienna);
})();

(function () {
    alert(myvar); // undefined
    var myvar = "local value";
    alert(zmienna);
})();

```

In the tutorial, I've read that JavaScript variables are not visible from function blocks. Well, first two alerts says correct values. It's strange then, because third alert says "undefined", despite fact that nothing has changed from previous function block. The fourth one, again, prints right value.

Could anybody explain me, what is happening here? I would be very glad, because tutorial says nothing more about that.