How do you stop an infinite loop in Javascript?

Solution 1:

2018 update:

In Chrome 67, if you have the DevTools open (F12), you can end the infinite loop without killing the whole tab:

  • Go to the Sources panel and click "Pause script execution".
  • Hold that same button and now select the "Stop" icon.

enter image description here

https://developers.google.com/web/updates/2018/04/devtools#stop

Solution 2:

I'm using Chome Version 45.0.2454.101

At the top right hand corner, at the hamburger menu, click on More Tools > Task Manager, and then kill the tab from there. This is if attempting to close the tab fails. Otherwise a simple 'X' on the tab kills it.

Solution 3:

At least with Chrome, you may be able to kill off the individual tab and not the whole application.

Randolpho has also informed me that IE8 has similar functionality.

Solution 4:

If you are using Chrome you can easily kill not responding tab:

  1. Open a new tab
  2. Press Shift + Esc to open Chrome's Task Manager
  3. Find your tab in the list (Should be the most memory consumer)
  4. Click End Process button

Important: Navigating to another tab is important, because JavaScript will caught your key press and do nothing because of its infinite loop.