javascript数据有六大基本类型:Number,String,Boolean,Null,Undefined,Symbol
,一种引用类型Object
javascript
typeof
检测基本类型typeof
能够用来检测除null
以外的基本类型,还能够检测函数java
instanceof
检测对象类型
注意:instanceof 后面必定要是对象类型,而且大小写不能错,该方法适合一些条件选择或分支数组
Object.prototype.toString.call(arg)
大小写不能写错,比较麻烦,但胜在通用。函数
zepto
封装的判断是否数组方法:spa
isArray = Array.isArray ||function(object){ return object instanceof Array }
underscore
判断给定变量是不是对象prototype
// Is a given variable an object? _.isObject = function(obj) { var type = typeof obj; return type === 'function' || type === 'object' && !!obj; };