Confused about hoisting

前端 未结 5 1441
感情败类
感情败类 2021-01-21 03:09

consider these slightly two different versions of hoisting...

mylocation = \"dublin\" 
function outputPosition() {
    alert(mylocation);
    mylocation = \"fing         


        
5条回答
  •  星月不相逢
    2021-01-21 03:35

    Once you declare variable using var keyword within a javascript function and no matter where you put this declaration - at the top of the function or at the buttom, it will be considered as local variable. So that is why you get undefined when you try to get value of such variable before var declaration.

提交回复
热议问题