Hoisting variables in JavaScript

后端 未结 5 1536
误落风尘
误落风尘 2020-12-06 20:50

I understand Hoisting of variables is done in Java Script. I am unable to get why it outputs as undefined

 do_something()
    {
    var foo = 2;    
    cons         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 21:34

    Only the declaration is hoisted, any assignment to a variable always stays where its originally from.

提交回复
热议问题