Is it possible to define a variable inside a function in JavaScript and have that variable visible both in its original scope and one scope above?
For example:
function mainFunction() {
function firstFunction() {
var var1 = 10;
secondFunction();
console.log(var2); // should be 20 (should be undefined in the scope above firstFunction())
console.log(var1); // should be 10
}
function secondFunction() {
var var2 = 20;
console.log(var2); // should be 20
console.log(var1); // should be undefined
}
firstFunction();
console.log(var2); // should be undefined
console.log(var1); // should be undefined
}