Hacker News new | ask | show | jobs
by davnicwil 2413 days ago
I don't see it as two kinds of null, there is a null value, and then there is the fact that no value has ever been defined, which is undefined.

It can be useful to have the latter case distinguished in a dynamic language because it can enable certain powerful patterns. At the end of the day, compressing both these cases to a single concept of null would be lossy. This may have certain advantageous implications for simplicity, but you're trading that off for language power. Which you favour more of course depends on the usecase.

2 comments

Or, use Maybe/Option and have as many levels of nonexistence as you want.

    Option[Option[Option[T]]]
Not that it would necessarily be very useful, but choosing 2 values of nonexistence is very arbitrary.

Usually zero or one level of nonexistence is enough.

There is yet a third type of missing value in JS: empty array slot. This appears when you create an array with a length but no values for indexes in that length, e.g. `new Array(100)`.

Edit: also `undefined` is a value in JS as well.