对js中 typeof 操作符的本质的一些疑问

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/csu_passer/article/details/83755168

首先,我们应该知道:

    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 操作符执行的本质是不是查找基本数据类型值的地址来判断该变量是什么类型的呢?(因为栈的大小是有限的)

如果不是这样,那是如何确定变量的数据类型的?

猜你喜欢

转载自blog.csdn.net/csu_passer/article/details/83755168