什么时候是javascript`Null`中变量的数据类型?

Suv*_*jah 3 javascript

实际上是否可以将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)
Run Code Online (Sandbox Code Playgroud)

Qan*_*avy 8

typeof永远不会返回"null",但有一个内部null类型:

结果类型:

  • 未定义: "未定义"
  • 空: "对象"
  • 布尔值: "boolean"
  • 编号: "数字"
  • 字符串: "string"
  • 对象(本机的,不实现[[Call]]): "object"
  • 对象(本机或主机并实现[[Call]]): "function"
  • 对象(主机并没有实现[[Call]]):实现定义,但可能不是"未定义","布尔","数字"或"字符串".

测试null的唯一方法是null使用===运算符直接与值进行比较.