I have this sample of code When i run updateBgColor()
in js dev console of navigator the color is updating after function call finished. Could someone explain this behavior and how can i force updating the color before sleep(4000);
Note: In my process sleep(4000)
will be replaced by long task that may take several seconds.
<html>
<head>
<script>
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
function updateBgColor()
{
document.bgColor="green";
sleep(4000);
}
</script>
</head>
<body></body>
</html>