Order of hoisting in JavaScript
问题 function g () { var x; function y () {}; var z; } I would like to know exactly what order the above code becomes when hoisted. Theory 1: Order between var s and function s remains as-is: function g () { var x; function y () {}; var z; } Theory 2: var s come before function s: function g () { var x; var z; function y () {}; } Theory 3: function s come before var s: function g () { function y () {}; var x; var z; } Which theory is correct? 回答1: Functions are hoisted first, then variable