最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Do infinite loops of JavaScript crash the browsers these days? - Stack Overflow

programmeradmin2浏览0评论

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?

Share Improve this question edited Jan 7, 2013 at 11:45 Cerbrus 73k19 gold badges136 silver badges150 bronze badges asked Jan 7, 2013 at 11:01 Abhishek MhatreAbhishek Mhatre 5573 gold badges9 silver badges16 bronze badges 3
  • 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
Add a ment  | 

1 Answer 1

Reset to default 11

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);
发布评论

评论列表(0)

  1. 暂无评论