DEV Community

Discussion on: ✨♻️ JavaScript Visualized: Event Loop

Collapse
 
miwsyed profile image
Syed Mustafa Naqvi

Hi, Lydia Hallie can you tell me what is the case with setInterval in call stack a combination of setTimeout and setInterval see the usecase below. Is setInterval also supposed to go to webAPI?



let c = 0;
let id = setInterval(()=> {
console.log(c++)
},200)

setTimeout(()=> {
clearInterval(id)
},2000)
// prints
/* 0
1
2
3
4
5
6
7
8 
9
and then stops  */
Enter fullscreen mode Exit fullscreen mode
Collapse
 
1option profile image
Maksim Rozhkov • Edited

2000/200 = 10 times

after 2 seconds we clear setInterval id