Abhishek Mhatre
Abhishek Mhatre

Reputation: 557

Do infinite loops of JavaScript crash the browsers these days?

I am learning JavaScript and am quite new in Programming and happened to land upon these infinite loops which were said to go on forever and crash the browser, but when I created one with these codes:

i=0;
while (i<10) {document.write(i);}

The browser just kept on going to load it and never did but the browser didn't crash?
So is it that the browsers these days are powerful enough to withstand infinite loops, or do I need a different infinite loop?

Upvotes: 3

Views: 8932

Answers (1)

Cerbrus
Cerbrus

Reputation: 72937

Yes, Infinite loops do still crash browsers (Or just the tab the JS is running in). However, most modern browsers can detect if a script's hanging / running a infinite loop, and give you the option to abort the script.

Also, a more efficient way to create a infinite loop, would be:

while(true);

Upvotes: 11

Related Questions