1

In Below, why does while loop run before document.body.style.backgroundColor assignment?

console.log("loadded");

const btn = document.getElementById("button");

btn.addEventListener("click", () => {
  document.body.style.backgroundColor = "red";
  const start = Date.now();
  const delaySeconds = 10;
  while (Date.now() < start + delaySeconds * 1000) {}
});
<button id="button">test</button>
Alexander Nied
  • 12,804
  • 4
  • 25
  • 45
user3502374
  • 781
  • 1
  • 4
  • 12
  • See also https://stackoverflow.com/questions/42986295/is-innerhtml-asynchronous/42986563#42986563 – jered Jun 18 '20 at 01:34

0 Answers0