我可能错过了一些简单的东西,但我不明白为什么当我在 console.log 之前声明变量时,它会在每个 console.log 中返回“未定义”
var timer;
var timerCalc = Math.random()*2000;
if (timerCalc > 1000){
timer === 1000;
console.log(timer);
} else if (timerCalc < 100) {
timer === 100;
console.log(timer);
} else {
timer === timerCalc;
console.log(timer + " = between 100 and 1000");
}
最佳答案
您正在执行 ===
(比较)而不是 =
(赋值)。使用后者。
关于javascript - 变量条件未按预期声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52763701/