我试图理解从互联网上找到的一段代码。我不明白为什么在 while 循环中它不是一个无限循环。如果我将其中的
calculator.appendChild
更改为例如 console.log
,它会一直运行下去。 window.location.hash = 1;
var calculator = document.createElement("div");
calculator.id = "height-calculator";
while (document.body.firstChild) {
calculator.appendChild(document.body.firstChild);
}
document.body.appendChild(calculator);
document.title = calculator.clientHeight;
基本上,在非空站点中总是有一个第一个子元素,因此条件始终为真。有人能解释一下为什么这样不会无限运行吗?