Hacker News new | ask | show | jobs
by goto11 1712 days ago
> Other languages refer to null as their billion dollar mistake

The "billon dollar mistake" as described by Tony Hoare was not nulls per se.

The billion dollar mistake was having a type system where null was a member of every reference type. This does not apply to language like JavaScript without static type checking, and it doesn't apply to type systems like TypeScript where null or undefined have to be explicitly specified as members of a type.

The undefined/null distinction solves an additional problem: In Java you don't know if a value is null because a field wasn't initialized correctly or because it was deliberately set to null. JavaScript allows you to distinguish between these two scenarios.

1 comments

exactly.. the 'only' billion dollar mistake in JS in regards to null is that typeof null === 'object' => true
It’s not undefined, therefore it’s an object. And because every type can be null, it makes sense that it’s just “object”, not “string” or whatever.
It it just a mistake or oversight in the definition of the language. It doesn't really make logical sense that a null is an object but a string is not an object.

It would kind of make sense in Java, where only object types can be null. But that distinction does not exist in JavaScript.

typeof null should be "null", just how typeof undefined is "undefined"

it is an implementation bug of netscape, null was represented by the zero pointer and objects where tagged pointer with a tag of zero, so when reading its tag null looked like an object.

there are solutions as x == null, x === null, and Object(x) == x allow you to check for null|undefined, null, and object values, but typeof null being "object" is purely a specification bug that it is too late to change.