Can someone explain to me why the second function within the first function is undefined?
var a = 1
function abc () {
alert(a);
function xyz () {
alert(a);
}
}
Can someone explain to me why the second function within the first function is undefined?
var a = 1
function abc () {
alert(a);
function xyz () {
alert(a);
}
}
xyz is an inner function which is private to abc function.
You cannot call xyz unless you make it public
This is due to the scope at which you are trying to execute xyz() (globally). xyz() can only be run inside of abc() - where it is defined in the local scope.