JavaScript变量详解
变量类型
基本数据类型:number,string,boolean,null,undefined
引用类型:object
新增:symbol ES6新增
我们可以用 typeof 运算符来查看值的类型,它但是JavaScript七种类型和它们的字符串值并不是一一对应:
typeof undefined === "undefined"; // true
typeof true === "boolean"; // true
typeof 42 === "number"; // true
typeof "42" === "string"; // true
typeof {name: "test" } === "object"; // true
// ES6中新加入的类型
typeof Symbol() === "symbol"; // true
NULL
其中,null比较特殊,typeof null === "object"; // true
正确的返回结果应该是"null",但这个 bug 由来已久,在 JavaScript 中已经存在了将近
二十年,也许永远也不会修复,因为这牵涉到太多的 Web 系统, “修复”它会产生更多的
bug。
因此,要使用复合条件来检测 null 值的类型