在我的输出中,从哪里出现" false"?

时间:2015-05-24 18:03:26

标签: 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!");
    }
slaying = false;

}

我的出局:

You hit!
false

我需要知道从哪里来的这个"假"在我出来的话?我知道我输出的第一行。我也清楚你的伤害和伤害这个圆形的功能。我只是想知道它是如何在执行时工作的。

1 个答案:

答案 0 :(得分:0)

当您在控制台中运行脚本时,while include会显示布尔值,就像放置

时一样
var foo = 'bar';

你的结果将是未定义的。

但是在您的网页中,您将无法获得结果。