Search code examples
javascriptecmascript-5

What does `ExpressionNoIn` mean in the ECMAScript spec?


I'm doing a bit of a deep dive into the for loop and encountered ExpressionNoIn in the spec at http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.3

What does it mean?


Solution

  • It is explained in section 11.14 "Comma Operator ( , )":

    Comma Operator ECMA Spec

    The *NoIn has the same structure, except that in excludes the use of the in keyword, section 11.8 "Relational Operators":

    Relational Operators ECMA Spec

    The spec says:

    The "NoIn" variants are needed to avoid confusing the in operator in a relational expression with the in operator in a for statement.

    As in may be used in two ways:

    for (var x in foo) { ... }
    

    Or:

    if ('x' in foo) { ... }
    

    The "NoIn" variants are there to make it impossible to use the second version of in above in the first expression of the for loop. So, the following code is invalid:

    for (y = 'x' in foo; y; y = false) { ... }