如今,无限循环的JavaScript会使浏览器崩溃吗? [英] Do infinite loops of JavaScript crash the browsers these days?

查看:100
本文介绍了如今,无限循环的JavaScript会使浏览器崩溃吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习JavaScript并且在编程方面相当新,并且恰好落在这些无限循环上,这些循环据说永远存在并且崩溃了浏览器,但是当我使用这些代码创建一个时:

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?

推荐答案

,无限循环仍会导致浏览器崩溃(或者只是JS运行的选项卡) )。 但是,大​​多数现代浏览器都可以检测脚本是否挂起/运行无限循环,并为您提供中止脚本的选项。

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

这篇关于如今,无限循环的JavaScript会使浏览器崩溃吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆