Does Javascript keep running when a app is in the background?

Trying to implement a kind of time out feature that if the user doesn’t interact with the app to have it log the person out.
Decided to try the javascript method of setTimeout
In basic testing it seemed to work. Once I had the app go into the background wait for it to time out and switch back to the app nothing happen.
It seems like setTimeout either stops or resets once the app doesn’t have focus anymore?
This is more Javascript question if it keeps running in the background? Is there a way to get it to keep running?

Even assuming that there was, think about what it would do to your users. Your app would become a battery-eating cancer. Please don’t even try to do this.