相关疑难解决方法(0)

'悬挂'JavaScript变量

我不完全理解为什么以下显示"悬挂"到最后.

var x = 'set';
var y = function () 
{
    // WHAT YOU DON'T SEE -> var x; 
    // is effectively "hoisted" to this line!

    if (!x) 
    { 
        // You might expect the variable to be populated at this point...it is not
        // though, so this block executes
        var x = 'hoisted'; 
    }

    alert(x); 
}

//... and this call causes an alert to display "hoisted"
y();
Run Code Online (Sandbox Code Playgroud)

任何指针将不胜感激.

javascript hoisting

31
推荐指数
2
解决办法
2720
查看次数

标签 统计

hoisting ×1

javascript ×1