类(class)要求我形成一个 while 循环,但我不断收到错误或无限循环。我做错了什么?
var understand = true;
while(understand= true){
console.log("I'm learning while loops!");
understand = false;
}
请您参考如下方法:
您使用的是赋值运算符 (=
) 而不是等号测试 (==
)。
使用:while(understand == true)
或者简化:while(understand)
评论更新:
===
表示值和数据类型必须相等,而 ==
将尝试在比较之前将它们转换为相同的类型。
例如:
"3" == 3 // True (implicitly)
"3" === 3 // False because a string is not a number.