0

I'm trying to get this function cleared with the clearInterval but it's not working.

setInterval( ()=>{ funca(10,3); }, 500);

But when i use the clearInterval it doesn't stop printing the result.

Here's my code:

funca = function(a,b){console.log(a+b);}
setInterval( ()=>{ funca(10,3); }, 500);
clearInterval(funca);

It keeps printing as you can see: The code running in console

So, how can i do it?

1 Answers1

1

setInterval returns a value. You should use this value as the parameter to clearInterval:

funca = function(a, b){ console.log(a + b); }
const intervalHandle = setInterval(() => { funca(10, 3); }, 500);
clearInterval(intervalHandle);
spender
  • 117,338
  • 33
  • 229
  • 351