Return value from nested function in Javascript
- by Chris Armstrong
I have a function that is set up as follows
function mainFunction() {
function subFunction() {
var str = "foo";
return str;
}
}
var test = mainFunction();
alert(test);
To my logic, that alert should return 'foo', but instead it returns undefined. What am I doing wrong?