How to understand Javascript in deep with var scope & closure? [duplicate]
问题 This question already has answers here : Javascript function scoping and hoisting (16 answers) Closed 2 years ago . I just can't understand why the the a1 = function ? and where is my value 1 that was passed to the fn() , whether it was overrwrited by var a ? the problem look like caused by the same names( var & function) ! function fn(a) { console.log("a1 = " + a); var a = 2; function a() { } console.log("a2 = " + a); } fn(1); // a1 = function a() { } // a2 = 2 function fnx(ax) { console.log