Have a Question?

If you have any question you can ask below or enter what you are looking for!

Question Detial

Say I have created a timer via:


(or I'm using setInterval())

Whilst that timer is ticking down, and before it expires, I decide to close the browser tab which that code is executing in. Does the browser automatically clean up the timer at that point (taking into account that I have not called clearTimeout() at all)?

I would like to know whether there is a possibility of code lingering in memory for long enough that, when the timeout value has been reached, it could still execute code. Or whether closing the tab means the timer is wiped from memory, and thus the function to call in the setTimeout() will never be executed.


Günter Zöchbauer

3:22am 17th January 2014

setInterval and setTimeout are the global context (via window object) methods. Then you close the tab or window all contexts will remove. Then you open new tab/window all contexts will created.

Gordon Linoff

3:24am 17th January 2014

The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed. Same goes for setTimeout(). You can give settieout to open window after 3 seconds on close. click and close. You will see that window wont be popping up.

See This

Marc Gravell

3:58am 17th January 2014

Both SetInterval() and SetTimeout() are a browser built-in schedulers. Which allows to setup function calls for execution after given period of time.

SetTimeout() can be cancelled by clearTimeout() method or on browser window closed.

SetInterval() method has same features as setTimeout. Which can be stopped by clearInterval call.

Functions used in setTimeout/setInterval are also referenced internally and tracked until complete, then cleaned up.