Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (15 sloc) 1.02 KB

Title: typeof null === "object"


Date: 1405539480


Authors: rasshofer


Text:

An initially confusing and counter-intuitive behavior of JavaScript is that the type determination of a variable being null using typeof returns "object".

var demo = null;
typeof demo; // "object"

The reason for this is that typeof will always return "object" for native non-callable objects. Actually, this stands since the beginning of JavaScript and the operator simply returns the type string of a given reference according to the table specified in the ECMAScript language specification ECMA-262 (see page 81).

A fix that would have resulted in typeof null === "null" has been proposed (via an opt-in), but was rejected as it was too late to fix the "problem" as a change of typeof null would break existing code like incorrect implementations of type checks.

You can’t perform that action at this time.