Null iterable in for-of?

Alexander Kit alex.kit at
Tue Jul 29 18:09:32 PDT 2014

Sorry for rising this subject again, but I am somewhat vexed about the
changed decision for the exception throwing when null is passed to the
for..of statement. I know, that my writing here wont change it now, but I
am a little bit uneasy about this dangerous precedent. So why it should not
throw any exceptions:

   - First considerations were right: it should behave the same as
   After making for..of throwable we lost the consistency. When we treat it
   from the consumers side, then it is clear, that this statements are
   equivalent, so they *must* be equal, when speaking about the null input.
   - For..of is the control flow statement and imho no exceptions should be
   thrown there, even when the input was invalid. Especially if the input was
   null - the statement should just not proceed, and this means we have
   zero iterations and will continue the execution.
   - “likely just masking a bug when passing null“. The main word here is
   “likely”, and it is not the argument for the exception throwing.
What about var
   foo; var bar = foo + 1 - foo is also undefined and addition is here, so
   is also likely a bug, and following the logic an exception here should be
   thrown also. If we continue to think in this direction, then every tiny
   failure will cause an exception, and this is definitely not good for the
   web. Exception throwing should be occurred, only when it is definitely the
   bug or when it can’t be proceeded due to the invalid input data.
   - “Fast fail is better”. Please no, not for the ecmascript, that’s why I
   love it and that’s how it was designed, please do not change this,
   especially when there is no need for this, and the arguments above have
   shown, that this is not the case here.

What I think is the correct behaviour? If the input is iterable it should
loop over it, otherwise (null / not iteratable type) should perform nothing
and continue with the execution, just like

Please, do not take this onto your account, this is more like a scream of
soul, and I hope I’m wrong ;)
Cheers, Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list