In the code below:
(function (){ function test(){};
printTest will display a "function" instead of "undefined", which makes sense because, as I understand it, any variable declarations always "go up" at the top of the execution context (which in this case is the context of the function's execution) This makes the declaration of the function "test ()" one that appears later in the current execution context. Now consider this code, where I actually assign a value to the declaration var "var test = 1".
(function (){ function test(){}; var test=1;
Then printTest now displays a "number", which means that the execution context now supports a different order. Can someone explain what really happened here?
javascript hoisting
Benny tjia
source share