Variable not hoisted

后端 未结 2 372
死守一世寂寞
死守一世寂寞 2021-01-21 01:33

In Javascript variables are hoisted to the top of the scope they are declared within.
However in the following code it seems that the variable myvar is not hois

2条回答
  •  滥情空心
    2021-01-21 01:46

    Variable declarations are hoisted, the assignments are not.

    By using var myvar anywhere in the function you create a locally scoped variable myvar, but if you follow it with = something then the assignment will take place in normal code order.

提交回复
热议问题