Function hoisting and the return statement
问题 I would expect this (reduced for the sake of example) function to run without a hitch, but it fails on account of fn2 is not defined : void function(){ var var1 = fn1(); var var2 = fn2(); function fn1(){}; return function fn2(){}; }(); How does the return statement exclude the function expression for fn2 from hoisting? 回答1: Only a function created with a function declaration is hoisted. The function in return function fn2(){}; is created with a (named) function expression so is not hoisted.