alert(typeof(1)); // number alert(typeof(NaN)); // number alert(typeof(Number.MIN_VALUE)); // number alert(typeof(Infinity)); // number alert(typeof("123")); // string alert(typeof(true)); // boolean alert(typeof(window)); // object alert(typeof(document)); // object alert(typeof(null)); // object alert(typeof(eval)); // function alert(typeof(Date)); // function alert(typeof(sss)); // undefined alert(typeof(undefined)); // undefined
typeof null == 'object'null 有属于自己的类型 Null,而不属于Object类型,typeof 之所以会判定为 Object 类型,是因为JavaScript 数据类型在底层都是以二进制的形式表示的,二进制的前三位为 0 会被 typeof 判断为对象类型,而 null 的二进制位恰好都是 0 ,因此,null 被误判断为 Object 类型