for-in loop VS in-operator

前端 未结 1 661
感动是毒
感动是毒 2021-01-23 18:29

I consider myself a JS veteran but just now for the first time I have realised that the for ... in loop does something very different from the in opera

1条回答
  •  温柔的废话
    2021-01-23 19:18

    So this brings me to my question: why is the in operator at all present in the for ... in loop?

    It isn't. The in token in the for … in loop construct is not an operator, just as much it is not one in the expression

    x = {in: 5}.in
    

    It's just one of the tokens that distinguishes a for ( … in … ) from a for (…; …; …) loop. Given that there is no for (…) statement, the role of the in token in a relational expression never collides with this.

    0 讨论(0)
提交回复
热议问题