We all know that when a function on completion can return a value. Now consider the following line of code
var t = setInterval(function() {
console.log('hey hi hello now 2 seconds have passed down');
} ,2000);
clearInterval(t);
Now, clearInterval()
takes the unique id returned by the setInterval()
function as an argument and this will only be returned once the function has completely run. What happens in my code, is that before my setInterval()
function runs, it gets cleared and this should not be possible as setinterval()
will not return anything until its callback function has been called.
How is the clearInterval()
function able to run before the setinterval()
function?