← Back to context

Comment by Sohcahtoa82

12 hours ago

Artificially increased is what's happening when you request a timeout of 0 and the browser always makes it 4 ms or more.

Imagine this code:

    let value = 0;

    (function tick () {
      value += 1;
      console.log(value);
      setTimeout(tick, 1);
    })();

If you let `tick()` run for 1 second, what would you expect the `value` to be? Theoretically, it should be around 1,000, because all you're doing is running a function that increments the `value` and then puts itself back onto the execution queue after a 1 ms delay. But because of the 4 ms delay that browsers implement, you'll never see `value` go above 250, because the delay is being artificially increased.