clearInterval()
stops the movingTab specified by setInterval()
, but when startTimer()
runs again, the tabInterval value is not 0 and is incrementing. What’s the problem? This issue doesn’t actually cause any serious problems with my functionality, but I’m curious as to why.
var tabInterval = null;
function startTimer() {
if(tabInterval === null) {
console.log("first : " + tabInterval);
tabInterval = setInterval(movingTab, 10000);
console.log("second : " + tabInterval);
}
}
function stopTimer() {
if(tabInterval !== null) {
console.log("third : " + tabInterval);
clearInterval(tabInterval);
tabInterval = null;
console.log("fourth : " + tabInterval);
}
}
If I do for(var i = 0; i < 999; i++) clearInterval(i)
, the time does not increase, but the value of tabInterval = setInterval(movingTab, 10000)
is not initialized to 0.
ex)
first run ->
first console : null
second console : 2
third console : 2
fourth console : null
second run ->
first console : null
second console : 11
third console : 11
fourth console : null
김태훈 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1