I have the following code snippet:
if (someCondition) { // clear globTimer first?? globTimer = setInterval(function() { someBlinkingCode; }, 1000); } else { clearInterval(globTimer); }
but this part of the code can be called several times, where someCondition will be true. This means that several intervals will be created, and not all of them will be destroyed. And after a while, the blink was more frequent than 1 second, so I added clearInterval(globTimer); instead of a comment. This change solved my problem, but is this solution ok? Can I call clearInterval() more than once for the same variable or call it for undefined ?
source share