This question has already been answered:
In the next experiment, we have one "outer" function outerFunction() and two inner functions, as well as two variables. The first of them is declared at the beginning of the external function, the second is also in the external, but between internal functions.
function outerFunction(){ var testVar1 = 'test1'; innerFunction1(); innerFunction2(); function innerFunction1(){ console.log('InnerFunction1() has been executed') } var testVar2 = 'test2'; function innerFunction2(){ console.log('testVar1: '+testVar1); console.log('testVar2: '+testVar2); } } outerFunction(); If we look at the console, we see that testvar2 is of type undefined . The same will happen if you declare this variable at the end of an external function.
I correctly understood that variables initialized at the beginning of an external function are first initialized, then internal functions? The declaration of the textVar2 variable is textVar2 stylistically correct, but still: when will it be initialized?