1
vrant
4y

How to make a endless loop program in JavaScript?

Comments
  • 6
    while (true);
  • 2
    @theabbie that wouldn’t (shouldn’t) actually work in a browser, however, as it leads browsers to stop JS execution on page. A much better alternative (that actually works) is: ’for (;;) {}’
  • 3
    @100110111 It does stop the current page, also, both infinite loops are equivalent. Crashing the browser will be difficult using any JS code, playing large media file might help in crashing.
  • 2
    @theabbie infinite for loop is pretty standard (at least I see it quite a bit in C and Java code that I’ve worked with, and I know it’s possible in JS, tho never had a reason to use it). Tbh I can’t think of a reason why somebody should use any infinite loop in front-end JS, but the infinite for loop shouldn’t crash your page just by the virtue of being there. Whatever the case, you’ll want some way of breaking out of the loop...
  • 0
    how bout setting a variable to True,
    then checking the loop against that variable?
    maybe browsers arent smart enough to identify it as an infinite loop ?

    and if they are, maybe setting said variable to 1, incrementing it up, if statement to prevent overflow and while loop waiting for it to be 0 might do the trick?
Add Comment