Menu
Sites
Language
clearInterval(interval); How to find out Interval is cleared?

clearInterval(interval);

How to find out Interval is cleared?

(interval === null) doesn't work

(interval === 0) doesn't work

(!interval)doesn't work

Thanks!

Edited on 04 05, 2019

Responses

4 Replies
Armaan-Ul- Islam

Try

( interval === undefined )

Thanks.

Onur Şahin

Well you can do

var interval = setInterval(function() {}, 1000);
interval = clearInterval(interval);
if (typeof interval === 'undefined'){

}

but what are you actually trying to do? clearInterval function is an always success function and it will always return undefined even if you call it with a NaN value, no error checking in there.

Marco Buettner
var interval = 0;

interval = setInterval(function() {}, 1000);

clearInterval(interval);

console.log(typeof interval); // get the type

 

Onur Şahin

Javascript is a pass by value language, meaning whatever you do with the parameter inside the function, it won't change the value of the variable inside the caller function. So interval variable stays with the same value after you call clearInterval.

 

Did you wrote interval  = clearInterval(interval); ? This should set interval to undefined thus typeof interval === 'undefined' should work.