I am making a game using Javascript, and to update the game I am using setInterval(). Should I use clearInterval() somehow on the window exit, or does it automatically stop?
The setInterval() method calls a function at specified intervals (in milliseconds). The setInterval() method continues calling the function until clearInterval() is called, or the window is closed.
In order to understand why setInterval is evil we need to keep in mind a fact that javascript is essentially single threaded, meaning it will not perform more than one operation at a time.
There are two methods for executing code at specific intervals. They are: setInterval() setTimeout()
setTimeout allows us to run a function once after the interval of time. setInterval allows us to run a function repeatedly, starting after the interval of time, then repeating continuously at that interval.
The browser is (or better: should be) clever enough to fully clean up a closed website. That includes aborting it's running connections and terminating scripts. Data that stays on your PC after you close the tab usually only includes stuff like browser history entries, cookies, local storage and cached data (e.g. scripts, stylesheets, images).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With