JS 类型判断方法简要汇总
基本类型
- 
除 null以外的基本类型:typeof value === '...'- JS 中的基本类型参见 JS 中的基本数据类型。
- typeof运算的返回值参见 JS 中 typeof 运算的返回值。
 
数组
- Array.isArray(arr)
- arr instanceof Array
- arr.constructor === Array
- Object.prototype.toString.call(arr) === '[object Array]'
对象
- obj instanceof Object
- obj.constructor === Object
- Object.prototype.toString.call(obj) === '[object Object]'
函数
- typeof fn === 'function'
- fn instanceof Function
- fn.constructor === Function
- Object.prototype.toString.call(fn) === '[object Function]'
null
- obj === null
- typeof obj === 'object' && !obj
NaN
- isNaN(number)
- Number.isNaN(number)