does this variable get hoisted no matter what?

回眸只為那壹抹淺笑 提交于 2019-12-13 05:51:26

问题


Does var foo get hoisted to the top of the stack even when the code inside the false block isn't ever going to be executed?

function foo(){
    if ( false ) {
       var foo = 'bar'; //will this be hoisted even if its never executed?
    }
}

I'm seeing that it is and was just confused...I didn't expect it to get hoisted in its wrapped in a false condition.


回答1:


Yes; the hoisting happens before the code is run, so whether or not the if statement comes out true or false isn't yet known.



来源:https://stackoverflow.com/questions/15648459/does-this-variable-get-hoisted-no-matter-what

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!