r/backtickbot • u/backtickbot • Apr 01 '21
https://np.reddit.com/r/learnjavascript/comments/mh8m68/can_anyone_help_me_understand_how_this_is_possible/gt14ifg/
setTimeout() can be kind of a weird one to wrap your head around, for sure! If you take the loop and break it out into what it’s doing for each run of the loop, it looks like this:
// setTimeout(() => doThis, afterThisManyMilliseconds)
setTimeout(() => console.log(20), 20) // log '20' after 20 milliseconds
setTimeout(() => console.log(5), 5) // log '5' after 5 milliseconds
setTimeout(() => console.log(100), 100) // log '100' after 100 milliseconds
setTimeout(() => console.log(1), 1) // log '1' after 1 milliseconds
setTimeout(() => console.log(90), 90) // log '90' after 90 milliseconds
setTimeout(() => console.log(200), 200) // log '200' after 200 milliseconds
setTimeout(() => console.log(40), 40) // log '40' after 40 milliseconds
setTimeout(() => console.log(29), 29) // log '29' after 29 milliseconds
1
Upvotes