typeof
基本数据类型:Undefined、Null、Boolean、Number 和 String
-
Undefined
、Boolean
、Number
、String
返回对应类型 -
NaN
返回number
类型 -
null
返回object
- new函数实例和对象返回
object
- 函数和class构造函数返回
function
console.log(typeof a); //'undefined'
console.log(typeof(true)); //'boolean'
console.log(typeof '123'); //'string'
console.log(typeof 123); //'number'
console.log(typeof NaN); //'number'
console.log(typeof null); //'object'
var obj = new String();
console.log(typeof(obj)); //'object'
var fn = function(){};
console.log(typeof(fn)); //'function'
console.log(typeof(class c{})); //'function'
instanceof
-
instanceof
返回true
/false
- instanceof代表原型,依靠对象proto追溯
console.log(a instanceof Object)
console.log(a instanceof Array)
网友评论