I am just showing the value of a in alert but I am getting a is undefined why? I will explain the problem:
First I call function with false parameter, it show alert with a = 1;. But when I pass true as parameter, it first show alert 2 (as expected it is local) but when again it show 2? Third it say a is undefined?
function ab(p){
a = 1;
if(p){
var a = 2
alert(a)
}
alert(a)
}
ab(false);
alert(a);
Unexpected result when ab(true)?