Hello, I’ve been researching this all day and have come up empty. Can someone explain what is going on here? See code below. I thought outer and inner functions would each run three times because I called the outer function three times. Scroll all the way down to see my comments at the bottom about why I’m confused.
<script>
window.onload = function() {
var outerFunction = function() {
var logThis = "Outer function ran.";
console.log(logThis);
var innerFunction = function() {
var logThisAlso = "Inner function ran.";
console.log(logThisAlso);
};
return innerFunction;
};
var functionCall = outerFunction();
functionCall();
functionCall();
/*
Result:
Outer function ran.
Inner function ran.
Inner function ran.
Why not returning the below?
Outer function ran.
Inner function ran.
Outer function ran.
Inner function ran.
Outer function ran.
Inner function ran.
*/
};
</script>