For-in Loop Vs In-operator
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 operator: 'length' in []; // true
Solution 1:
So this brings me to my question: why is the
in
operator at all present in thefor ... 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.
Post a Comment for "For-in Loop Vs In-operator"