When working on some Javascript for a web application, I noticed that I had used setTimeout, but I had tried to clear it with clearInterval and it stopped the timeout from occurring in Google Chrome and Internet Explorer 9.
Are clearTimeout and clearInterval interchangeable?
Here’s a JSfiddle with an example of what I’m talking about.
No, they are not interchangeable.
Sure, some browsers may very well share the same code to clear intervals and timeouts the same way, but does not mean they are interchangeable and you are most certainly not guaranteed that they would work the same across all browser implementations. It comes down to these two methods being defined differently for different purposes and therefore you should use them for their designated uses.. Otherwise, you’re just asking for trouble.