Javascript function scoping and hoisting

后端 未结 18 2962
孤街浪徒
孤街浪徒 2020-11-21 04:20

I just read a great article about JavaScript Scoping and Hoisting by Ben Cherry in which he gives the following example:

var a = 1;

function b() {
    a =          


        
18条回答
  •  半阙折子戏
    2020-11-21 05:01

    function a() { } is a function statement, which creates an a variable local to the b function.
    Variables are created when a function is parsed, regardless of whether the var or function statement gets executed.

    a = 10 sets this local variable.

提交回复
热议问题