[英]Why is my IF statement not executed?? And why does the interval continue to run even when I inserted a clearStatement call
The If statement is not being executed. If语句未执行。 I dont understand why? 我不明白为什么?
the only way I can clear the interval is if I print the command myself without the any if statements. 我可以清除间隔的唯一方法是,如果我自己打印命令而没有任何if语句。
var number = 0;
function addThis(){
return number +=1;
}
var mySID = setInterval(addThis, 1000);
if(number === 10){
clearInterval(mySID);
number;
}
It is running; 它正在运行; it's just not evaluating to true, so the "then" doesn't run. 它只是没有评估为真,因此“ then”不会运行。 Your if
statement runs immediately after the call to setInterval
, so number
is still 0. It won't be 10 for another 10 seconds, but by then the if
statement has long since finished. 您的if
语句将在调用setInterval
之后立即运行,因此number
仍为0。在接下来的10秒钟内不会为10,但是到那时if
语句已经结束了很长时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.