Why is it for ... unsuccessfully elegant, but ... for throwing an Exception?

Why is this

for (let e in null) void e 

gracefully crashes but

 for (let e of null) void e 

throws a TypeError ? Does this lead to inconsistency?

+8
javascript ecmascript-6 foreach
source share
1 answer

for...of only works with iterable objects (i.e. objects that implement the iterative protocol ), which null is not one of them. While for...in works with all values.

+6
source share

All Articles