Javascript 在我的输出中,从何而来;假;?

Javascript 在我的输出中,从何而来;假;?,javascript,function,loops,while-loop,Javascript,Function,Loops,While Loop,以下是我的意见: var slaying = true; var youHit = Math.floor(Math.random()*2); var damageThisRound = Math.floor(Math.random()*5 + 1); var totalDamage = 0; while (slaying){ if(youHit){ console.log("You hit!"); } else{ console.log("You missed!");

以下是我的意见:

var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;

while (slaying){
if(youHit){
    console.log("You hit!");
    }
else{
    console.log("You missed!");
    }
slaying = false;

}
我的发言:

You hit!
false

我想知道我的输出中这个“假”字是从哪里来的?我知道我的第一行输出。我也很清楚你打坏了这轮函数。我只是想知道它在执行时是如何工作的

当您在控制台中运行脚本时,while包含将显示布尔值结果,就像您在

var foo = 'bar';
因此,您将具有未定义的属性


但是在你的网页中,你不会得到结果。

我在JSFIDLE中运行了你的代码,没有在控制台中得到第二行,只是第一行。但是我的codecademy编译器显示了这一行。这可能是codeacademy正在添加的额外内容-我不担心,它不会登录到真正的应用程序中,至少不会从该代码中获得