js数据类型
简单数据类型:number、string、boolean、null(空对象的指针)、undefined(已声明未初始化)
复杂数据类型:object
数据类型判断
- typeof
typeof
返回值只有undefined、boolean、number、string、object、function这几个值中的一个,返回值是字符串
typeof 23 ⇒ “number”
typeof ‘aaaa’ ⇒ “string”
typeof true ⇒ “boolean”
typeof null ⇒ “object”
typeof [1,2] ⇒ “object”
typeof {a:2, b:3} ⇒ “object”
typeof undefined ⇒ “undefined”
typeof error(错误)⇒ “undefined”
undefined值是派生自null,所以null==undefined ⇒ true
instanceof
object instanceof constructor
constructor包含Object/Function/Date/Array等等eg:
var m = {a:2, b:3};
m instanceof Object ⇒ true
m instanceof Function ⇒ false