I'm not quite sure why it is happening and it would be great if someone could explain this to me.
So i got the following code:
var text = 'yes';
(function f() {
alert(text);
})();
And it alerts 'yes' as expected. But if I expand it like this:
var text = 'yes';
(function f() {
alert(text);
var text = 'no';
})();
I would pretty much expect this to alert 'yes' too and then overwrite the text variable in the local scope. But instead it alerts undefined.
This is tested in current Chrome and Firefox so this seems to be a wanted behavior?!