请问一下各位大大
<!DOCTYPE html>
<html>
<body>
<p> line 1 </p>
<p id="demo"></p>
<p> line 2 </p>
<script>
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var i = 0;
var text = "";
while (cars[i]) {
text += cars[i] + "<br>";
i++;
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
line 1
BMW
Volvo
Saab
Ford
line 2
我知道 getElementById是抓取ID的属性的物件
可是<p id="demo"></p>并非函数 也没呼叫 为何会跳去先执行
document.getElementById("demo").innerHTML = text; 而非按照顺序由上往下执行呢?