JS中有五种基本类型 String, Number,Boolean,Undefined,Null以及一种复杂数据类型Object
typeof 操作符
由于js中的变量是松散类型的,所以它提供了一种检测当前变量的数据类型的方法,也就是typeof关键字.
typeof 123 //Number
typeof 'abc' //String
typeof true //Boolean
typeof undefined //Undefined
typeof null //Object
typeof { } //Object
typeof [ ] //Object
typeof console.log() //Undefined
null类型进行typeof操作符后,结果是object,原因在于,null类型被当做一个空对象引用。
null类型被看做空对象指针,前文说到null类型也是空的对象引用。
对于复杂的数据类型Object(主要分为三种,Object,Array,Function)
复杂数据类型在栈中存储数据名和一个堆的地址,在堆中存储属性及值,访问时先从栈中获取地址,再到堆中拿出相应的值
浙公网安备 33010602011771号