Remix.run Logo
ngruhn 3 hours ago

You can't get rid of undefined. You can't ban null either. They're both used in the core language all over the place:

undefined camp:

- out of bounds array index access [1,2,3][42]

- non existent object key access {}.foo

- array.find(...) no result

- ...

null camp:

- document.querySelector(...) no result

- regex.match(...) no result

- ...

sheept 2 hours ago | parent [-]

In general the language uses `null` if it would otherwise return an object (similar to Java; this is also why null is an object but not really in both languages), while `undefined` is used if it could otherwise return any value.

Could the language have done without both null and undefined? Definitely. But it's here and here to stay.

Though, it's not the only language with two nulls. Julia has nothing and missing, though their semantics are more well defined and with different behaviors than in JavaScript.