Checking whether clearInterval has been called?

swajak picture swajak · Sep 24, 2009 · Viewed 28.2k times · Source

Given this code:

bob = setInterval(function, 1000);
clearInterval(bob);

Is there now a way to know if that interval has been cleared?

Currently, I keep track of this myself, by unsetting 'bob', but I'm curious if my extra line of code is unnecessary:

clearInterval(bob);
bob = null;
if (!bob) itIsCleared();

Thanks!

Answer

Rich picture Rich · Sep 24, 2009

The return value of setInterval is just a unique id you use to pass back to clearInterval. It's not a structured object with any additional information, nor does it get set to null when you call clearTimeout.