Hacker News new | ask | show | jobs
by crdrost 8 days ago
If you're a type purist then undefined looks nicer... It'd be like being upset at booleans because things get coerced to them or some 'ish.

No: it's the type that has one inhabitant—it's not that type's fault that it appears as a default argument or var or was left out of JSON... So long as typeof null === "object", null is the absurd one

1 comments

undefined is not less absurd because there are parts of the standard that allow you to differentiate between

  undefined 
and a non-initialized value.

Of course you shouldn't do that, but I once encountered a library that behaved differently depending on whether an option in an options bag object was not present or explicitly set to undefined.

You can run into similar ugliness with function parameters, if you do evil things like using

  arguments
And of course you can explicitly check keys of objects, including parameters that are going to be destructured.

All not things you should do, but taints the "purity" argument, doesn't it? :D