This question already has an answer here:
function foo(a) {
function a(){
return 8;
}
return a();
y = 9;
} console.log(foo() + " " + y);
This gives an undefined error for variable y.
function foo(a) {
y =9;
function a(){
return 8;
}
return a();
}console.log(foo()+ " "+ y);
This prints 8 9 in browser's console. if we declare a variable without var keyword than it becomes global variable, why first function does not follow the idea ?
Aucun commentaire:
Enregistrer un commentaire