Reputation: 20249
Why is it that
for (let e in null) void e
fails gracefully, but that
for (let e of null) void e
throws a TypeError
?
Doesn't this result in an inconsistency?
Upvotes: 8
Views: 96
Reputation: 190956
for...of
only works on iterable objects (i.e. objects implementing iterable protocol) which null
is not either of these. Whereas for...in
works on all values.
Upvotes: 6