js的基本数据类型:string,boolean,number,null,undefined,symbol(ES6)prototype
引用数据类型:Object对象
判断基本数据类型:typeof ,须要注意的是null返回Object原型
判断引用类型:instanceof ,判断对象的原型 任何function 和 Object都有一个原型Objectstring
共通的方法io
Object.prototype.toString.call(须要检测的数据)console
- Object.prototype.toString.call(1): [object Number]
- Object.prototype.toString.call(NaN): [object Number]
- Object.prototype.toString.call("1"): [object String]
- Object.prototype.toString.call(true): [object Boolean]
- Object.prototype.toString.call(null): [object Null]
- Object.prototype.toString.call(undefined): [object Undefined]
- Object.prototype.toString.call({}): [object Object]
- Object.prototype.toString.call({a: "a"}): [object Object]
- Object.prototype.toString.call(console.log): [object Function]
这里除了对NaN的判断其余都符合预测function
对于NaN的判断object
isNaN(v)数据类型
(new Set([NaN, v])).size引用