In the function outer
, I am returning a function that uses the same name as a variable declared/defined inside outer
.
Why then is a closure not created? Why does the following code print undefined
, and not Yolo!
?
function inner(){
console.log('theVar', theVar);
}
function outer(){
var theVar = 'Yolo!';
return inner;
}
console.log('Starting...');
outer()();