数据类型
-
基本数据类型(原始数据类型)
Number、String、Boolean、Null、Underfined、Symbol(ES6引入的一种数据类型,表示独一无二的值) -
引用数据类型
Object、Array、Function、Date、Error、RegExp、Math.
console.log(typeof 1 ) Number
console.log(typeof '1' ) String
console.log(typeof true ) Boolean
console.log(typeof function(){}) Function
console.log(typeof underfined ) underfined
console.log(typeof [] ) Object
console.log(typeof {} ) Object
console.log(typeof null ) Object
console.log(typeof Symbol()) symbol
在使用typeof检测数据类型的时候,Object分为两种,一种是object类型,一种是function类型。在ECMAScript规则中定义,Object(does not implement [[call]]) 检测出来为’object’, Object(implements[[call]]) 检测出来是’function’,只要是[[]]括起来的是内置属性,是供浏览器使用的,没有报漏出来, 比如[[scope]],代表函数作用域的一个内置属性。
3. 为什么null为object,这究竟是为什么?
为什么会出现这种情况?因为在JS的最初版本中,使用的是32位系统