setTimeout(), setInterval(), and requestAnimationFrame()
Why might the timeout execute later than expected?
let start = performance.now();
while (performance.now() - start < 1000) {
// Busy loop
}
setTimeout(() => console.log('Timeout'), 0);
let start = performance.now();
while (performance.now() - start < 1000) {
// Busy loop
}
setTimeout(() => console.log('Timeout'), 0);