A somewhat basic question here. I can see what is going on but I can't really understand why it would work this way.
a = false;
var k = function() {
console.log(a);
var a = true
console.log(a);
}();
I would expect the log to read "false, then true" but "a" undefined at first. Can someone please elaborate why it does this.
Ps. I'm not looking for an answer telling me what I should do, I'm looking for an explanation of the inner workings of this piece of JavaScript.
Thanks in advance