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?
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?
- You could try an infinite loop that adds information to an array. – Sanchit Commented Jan 7, 2013 at 11:04
- Did you get any javascript errors? – Leandro Barreto Commented Jan 7, 2013 at 11:18
- "withstand infinite loops" - there is a difference between "infinite loop" and "continuous processing". I assume you're interested in the latter. In that case search for setTimeout function and see how you can partition your work in correct chunks – Liviu T. Commented Jan 7, 2013 at 11:48
1 Answer
Reset to default 11Yes, 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);