From a language design perspective, why:
if('k' in null);
TypeError: Cannot use 'in' operator to search for 'k' in null
BUT:
for('k' in null);
prints undefined
in ECMAScript spec:
Is it the language design flaw?
From a design perspective, it's hard to say what the appropriate return value of k in null
should be (true
is clearly wrong, but false
is misleading), but it's easy to say that in the for-in
statement, you should just skip the loop.
I don't agree with this decision at all - I think that for (k in null)
should throw an error, especially if running in strict mode. But you can see how the difference would arise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With