Someone can explain me why this variable become "undefined" ?
var a=1;
var cond=false;
alert(a);
setTimeout(function(){
alert(a); // <---------------- WHY IS UNDEFINED????
alert(cond);
if (cond==true) var a=2; // <------ IF I COMMENT THIS OR SET cond=false, WHY a IS UNDEFINED???
alert(a);
}, 500);
Thanks.