Why Does clearInterval only works the first time?

You are getting failed logged because clearInterval returns undefined even when it is successful.

So your removeInt function,

if(clearInterval(myInt)) {console.log('success')} else {console.log('fail')}

is getting evaluated like this,

if(undefined) {console.log('success')} else {console.log('fail')}

Here’s a doc about clearInterval for more info, https://developer.mozilla.org/en-US/docs/Web/API/clearInterval

Leave a Comment