I have a problem understanding the way in which setInterval
and clearInterval
work in JavaScript.
I have read different articles on these two functions but I am still confused.
Given the fact that JavaScript is single thread
then when we call test=setInterval(function(){}, t)
we will schedule our function to be executed every t
miliseconds. Unless we clearInterval(test)
.
- What does that mean? Does it mean that by
clearInterval
wecancle
thesetInterval
which is already in the queue of JavaScript? - What would happen if we
setInterval
several times butclearInterval
only once? - Can we
clearInterval
insetInterval
? - How JavaScript handles the scheduled process?