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
var outerFunction = function () {
var a = 5;
innerFunction(a);
}
var innerFunction = function (a) {
alert(a);
}
outerFunction();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With