JS数据类型

113 阅读1分钟

一:JS六大数据类型:Number、String、Boolean、Undefined、Null和Object,js自动对内存进行垃圾回收。

1.布尔值

下面6个值被转为false

undefined、null、false、0、NaN、''或""

null == undefined //true,表示值的空缺
null === undefined //false

2.typeof返回一个值的数据类型(instanceof运算符用来测试一个对象在其原型链中是否存在一个构造函数的prototype属性)

typeof 123  //"number"
function f(){}  typeof f //"function"
typeof null  //'object' 可以把null看作一个特殊的对象,"非对象"
typeof undefined  //'undefined'
typeof NaN  //'number'
typeof window   typeof {}   typeof []//'object'