Empty for loop - for(;;)

前端 未结 4 1852
青春惊慌失措
青春惊慌失措 2020-12-01 13:06

I was exploring the Google Closure Compiler, and one thing I noticed was that it converts while(true) into for(;;).

Both do hang the browse

4条回答
  •  独厮守ぢ
    2020-12-01 13:46

    From the ECMAScript language specification:

    IterationStatement : for (ExpressionNoIn_opt ; Expression_opt ; Expression_opt) Statement

    If the first Expression is present, then

    1. Let testExprRef be the result of evaluating the first Expression.
    2. If GetValue(testExprRef) is false, return (normal, V, empty).

    Since the first expression (the second argument to for) is not present, this section is never run, so the for loop does not exit.

提交回复
热议问题