0
I’m studying the timing function in Javascript and I’m not able to make setInterval() stop through clearInterval()
var timer = function(){
setInterval(() => {
console.log(count);
count++
}, 200)}
var stop = function(){
setTimeout(() => {
clearInterval(timer)
console.log('executei');
}, 2000)
}
timer()
stop()
On the console to see that the stop function is apparently running, but the timer continues to run.
index.js:5 1
index.js:5 2
index.js:5 3
index.js:5 4
index.js:5 5
index.js:5 6
index.js:5 7
index.js:5 8
index.js:5 9
index.js:14 executei
index.js:5 10
index.js:5 11
index.js:5 12
index.js:5 13
index.js:5 14
index.js:5 15
index.js:5 16
index.js:5 17
var timer has to receive setInterval, but is receiving Function.
– Benilson