为什么这个while会导致无限循环?
meows = true;
while (meows = true) {
console.log('MEOW!');
meow = false;
}
console.log('Sorry, no meowing allowed.');
因为求值的表达式是一个赋值(而且循环内部的meow
中也有一个错别字),所以正确的版本是:
meows = true;
while (meows == true) {
console.log('MEOW!');
meows = false;
}
console.log('Sorry, no meowing allowed.');
错误赋值=
与实际相等==
是一种常见的错误