Do infinite loops of JavaScript crash the browsers these days?

自古美人都是妖i 提交于 2019-12-10 21:42:58

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/14194540/do-infinite-loops-of-javascript-crash-the-browsers-these-days

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!