基本数据类型
Number、String、null、undefined、boolean
引用数据类型
Object、function、Array、RegExp、new Date、 Math 实例对象。。。 function
es6新增数据类型
Synbol
其他
NaN
检测数据类型
var fn = funcion(){};
var obj = {};
var num = 1;
- typeof
typeof NaN => "number"
typeof null =>"object"
typeof 2 => "number"
typeof "aa" => "string"
typeof fn => "function"
typeof obj => "object" - instanceof
"aa" instanceof String => true
fn instanceof Function => true
obj instanceof Object => true
1 instanceof Number => false
number instanceof Number => false;
NaN instanceof NaN => TypeError: Right-hand side of 'instanceof' is not an object
false instanceof Boolean => false
3.toString
Object.prototype.toString.call('') ; // [object String]
Object.prototype.toString.call(1) ; // [object Number]
Object.prototype.toString.call(true) ; // [object Boolean]
Object.prototype.toString.call(Symbol()); //[object Symbol]
Object.prototype.toString.call(undefined) ; // [object Undefined]
Object.prototype.toString.call(null) ; // [object Null]
Object.prototype.toString.call(new Function()) ; // [object Function]
Object.prototype.toString.call(new Date()) ; // [object Date]
Object.prototype.toString.call([]) ; // [object Array]
Object.prototype.toString.call(new RegExp()) ; // [object RegExp]
Object.prototype.toString.call(new Error()) ; // [object Error]
Object.prototype.toString.call(document) ; // [object HTMLDocument]
Object.prototype.toString.call(window) ; //[object global] window 是全局对象 global 的引用