Why does typeof null return "object"?

Why does typeof null return "object"?

ยท

1 min read

๐—ฅ๐—ฒ๐—ฎ๐˜€๐—ผ๐—ป ๐Ÿญ: Because of the table specified in ECMA-262.
๐—ฅ๐—ฒ๐—ฎ๐˜€๐—ผ๐—ป ๐Ÿฎ: It might be a bug

Let's understand this:

In the ๐—ถ๐—ป๐—ถ๐˜๐—ถ๐—ฎ๐—น ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ผ๐—ณ ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ all values were stored in ๐Ÿฏ๐Ÿฎ ๐—ฏ๐—ถ๐˜๐˜€ ๐˜‚๐—ป๐—ถ๐˜๐˜€, where:
The ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ ๐Ÿญโ€“๐Ÿฏ ๐—ฏ๐—ถ๐˜๐˜€ contain the ๐˜๐˜†๐—ฝ๐—ฒ ๐˜๐—ฎ๐—ด
The ๐—ฟ๐—ฒ๐—บ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด ๐—ฏ๐—ถ๐˜๐˜€ contained the ๐—ฎ๐—ฐ๐˜๐˜‚๐—ฎ๐—น ๐—ฑ๐—ฎ๐˜๐—ฎ

The ๐˜๐˜†๐—ฝ๐—ฒ ๐˜๐—ฎ๐—ด for ๐—ผ๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜๐˜€ was ๐Ÿฌ.

The ๐—ป๐˜‚๐—น๐—น ๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฒ, however, was ๐—ฟ๐—ฒ๐—ฝ๐—ฟ๐—ฒ๐˜€๐—ฒ๐—ป๐˜๐—ฒ๐—ฑ as the ๐—ก๐—จ๐—Ÿ๐—Ÿ pointer, ๐˜„๐—ต๐—ถ๐—ฐ๐—ต ๐˜„๐—ฎ๐˜€ ๐Ÿฌ๐˜…๐Ÿฌ๐Ÿฌ for most platforms. As a result of this ๐˜€๐—ถ๐—บ๐—ถ๐—น๐—ฎ๐—ฟ๐—ถ๐˜๐˜†, ๐—ป๐˜‚๐—น๐—น ๐—ต๐—ฎ๐˜€ the ๐Ÿฌ ๐˜๐˜†๐—ฝ๐—ฒ ๐˜๐—ฎ๐—ด, ๐˜„๐—ต๐—ถ๐—ฐ๐—ต corresponds ๐˜๐—ผ ๐—ฎ๐—ป ๐—ผ๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜.

There have been ๐—ฑ๐—ถ๐˜€๐—ฐ๐˜‚๐˜€๐˜€๐—ถ๐—ผ๐—ป๐˜€ in the ๐—˜๐—–๐— ๐—”๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ working group proposing the following ๐—ฐ๐—ต๐—ฎ๐—ป๐—ด๐—ฒ:
๐˜๐˜†๐—ฝ๐—ฒ๐—ผ๐—ณ ๐—ป๐˜‚๐—น๐—น === "๐—ป๐˜‚๐—น๐—น"; // true

But ๐—ถ๐˜ ๐˜„๐—ฎ๐˜€ ๐—ฟ๐—ฒ๐—ท๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ and ๐—–๐—ฟ๐—ผ๐—ฐ๐—ธ๐—ณ๐—ผ๐—ฟ๐—ฑ pointed out: I think ๐—ถ๐˜ ๐—ถ๐˜€ ๐˜๐—ผ๐—ผ ๐—น๐—ฎ๐˜๐—ฒ ๐˜๐—ผ ๐—ณ๐—ถ๐˜… ๐˜๐˜†๐—ฝ๐—ฒ๐—ผ๐—ณ. The change proposed for the typeof null will break the existing code.

For an in-depth explanation, you can read the article by Axel Rauschmayer.

ย