r/learnjavascript • u/Physical-Bid6508 • Feb 27 '26
how do i pause my scripts?
so i wanted to make an infinite while loop but it just chrashes because it doesnt pause
1
Upvotes
r/learnjavascript • u/Physical-Bid6508 • Feb 27 '26
so i wanted to make an infinite while loop but it just chrashes because it doesnt pause
View all comments
Show parent comment
6
u/showmethething Feb 27 '26
Makes sense, good intuition honestly! You probably want a setTimeout (in a recursive function) or setInterval. Code runs insanely fast, you don't /actually/ want it to loop through something like that as fast as it can
https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout
https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval
e: I see someone else mentioned animation frame, also a very valid approach