In JavaScript what does for(;;){…} do?

前端 未结 5 1001
感动是毒
感动是毒 2021-01-26 08:40

I\'ve seen this in some JavaScript code but I don\'t get what it does.

for(;;){

  //other code

}

I\'m used to the for(i=0;i

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 09:43

    for (;;) is the exact same syntax. You're allowed to leave out parts that go between the semicolons, even all of them. If you leave the condition out, it's assumed to be true, so it results in an infinite loop. You can of course still exit with break or return or whatnot, hence making it not useless.

提交回复
热议问题