1. 程式人生 > >對js中 typeof 操作符的本質的一些疑問

對js中 typeof 操作符的本質的一些疑問

首先,我們應該知道:

    typeof null === "object;//true;

但這是為什麼呢?在網上查詢資料有這樣的答案:

Because the initial version of JS was based on 32-bit systems, which stored type information of variables in the lower bits for performance considerations. Those start with 000 are objects, and all the bits of null are zero, so it is erroneously treated as an object. Although the current code of checking internal types has changed, this bug has been passed down.

由此我們可以猜想:是不是所有的基本資料型別的儲存地址具有一定的規律性呢?如果是這樣的話,那麼typeof 操作符執行的本質是不是查詢基本資料型別值的地址來判斷該變數是什麼型別的呢?(因為棧的大小是有限的)

如果不是這樣,那是如何確定變數的資料型別的?