Questions on Javascript hoisting

后端 未结 4 464
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 08:12

While I was reading about Javascript hoisting, I tried the following. I am not sure why the first one and second one output differently. Thanks in advance. (I am not even su

4条回答
  •  春和景丽
    2020-11-27 09:08

    The declaration of thee local variable in the if block in the second example is hoisted to the entire function.

    Thus, me in the function always refers to the local variable, not the global.

    However, the value of the variable is not hoisted, so it's always undefined and the if is never entered.

提交回复
热议问题