I am learning javascript by myself.Today I came across with a code example which is quite confusing.
function fool(a, b){
if(b)
var c = "Mary"
alert(c);
}
fool(1, true); //Returns "Mary"
fool(1, false); //Returns undefined instead of error
On the other hand if I do this
function fool(a, b){
//if(b)
// var c = "Mary"
alert(c);
}
fool(1, true); //Firebug error: ReferenceError: c is not defined
fool(1, false);
An error is occurring on the first chance. How is so ?