DEV Community

Discussion on: ✨♻️ JavaScript Visualized: Event Loop

Collapse
 
jonasroessum profile image
Jonas Røssum

Really nice article!
One thing I was confused about was

invoke bar. bar returns a setTimeout function.
Enter fullscreen mode Exit fullscreen mode

Doesn't setTimeout return an id that you can pass to clearTimeout? 🤔

Collapse
 
jagajastic profile image
Ibrahim Joseph M.

Yes, It does Jonas, so lets say


let id = setTimeout( () => {
return "hey"}, 1000);

console.log(id) // you will get 1

let id2 = setTimeout( () => {
return "hey"}, 1000);

console.log(id2) // you will get 2

Collapse
 
thamerbelfkihthamer profile image
thamer belfkih

thank guys to point out this detail, in the same context what's the purpose of this Id and it is used by the web API or the call stack for some purpose? thanks in advance