Suggest an editImprove this articleRefine the answer for “typeof null”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`typeof null`** returns `"object"` because of a **historical bug** in JavaScript that appeared in the very first version of the language (1995) and stuck around for compatibility. **Key point:** Because of this bug, you cannot rely on `typeof` alone to check for `null`; the correct way is `value === null`.Shown above the full answer for quick recall.Answer (EN)Image## Short answer ```javascript typeof null === "object" ``` Result: `"object"` --- ## Why this happens This is a **historical bug** in JavaScript, which appeared as far back as the very first version of the language (1995) and **stuck around for the sake of compatibility**. --- ### Historical reason In early versions of JS, values were stored as **32-bit tagged data**: - the first **3 bits** indicated the **data type** - the remaining **29 bits** held the value itself Objects used the **type tag** `000` (three zeros at the start of the 32-bit value). And for `null`, **the entire value consisted of zeros** (`0x00`). So when checking `typeof null`, the engine saw: "ah, the first three bits are `000` → this is an object". That's how this came to be: ```javascript typeof null // "object" ``` --- ## Why this was not fixed Because millions of old scripts across the internet may depend on this behavior. Fixing it would cause massive breakage. > So the ECMAScript specification left this as a **"known bug"**, > but **officially documented** it. --- ## How to correctly check for `null` Because of this bug, **you cannot rely only on** `typeof` to check for `null`. ### Incorrect: ```javascript if (typeof value === 'object') { // could be null! } ``` ### Correct: ```javascript if (value === null) { console.log('This is null'); } ``` or if you want to distinguish null from other objects: ```javascript if (typeof value === 'object' && value !== null) { console.log('This is an object, but not null'); } ``` --- ## Illustrative example ```javascript console.log(typeof null); // "object" console.log(typeof {}); // "object" console.log(typeof []); // "object" console.log(null === {}); // false console.log(null === undefined); // false ``` > All three (`null`, `{}`, `[]`) return `"object"`, > but these are **different data types**. --- ## Summary | Check | Result | Explanation | |---|---|---| | `typeof null` | `"object"` | A historical implementation bug | | `null === null` | `true` | The value equals itself | | `typeof undefined` | `"undefined"` | Expected behavior | | `typeof {}` | `"object"` | A genuine object | | `typeof []` | `"object"` | An array is a subtype of object |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.