I define the variable “a” in the outerFunction. I want to use it in my innerFunction. How come this doesn’t work, and what is the best way to pass data between nested functions?
var outerFunction = function () {
var a = 5;
innerFunction();
}
var innerFunction = function () {
alert(a);
}
outerFunction();
You have to add parameter to inner function and pass value to it from outer function.
Live Demo