实际上是否可以将Null
数据类型作为typeof
函数的返回值 - 如果是这样的话会产生哪种结果,何时实际是Null
类型的变量?
typeof myVAR; //gives me "undefined" before the variable declaration
var myVAR;
typeof myVAR; //also gives me "undefined"
myVAR = null; //assigned the null object
typeof myVAR; //gives me "Object" (which I guess makes sense because `null` is an object and that's what I assigned to the variable)
答案 0 :(得分:8)
typeof
never returns "null"
,但有一个internal null type:
测试null的唯一方法是使用null
运算符直接与===
值进行比较。