1、typeof
是和基本类型及function检测,遇到null失效。
typeof "100" ---->string
typeof 100 ---->number
2、instanceof
是和自定义对象,也可以用来检测原生对象。遇到window以及iframe失效
[1,2] instanceof Array === true
new Object() instanceof object === true
3、{}.toString()
Object.prototype.toString.apply([]) === "[Object Array]" ------>返回true
Object.prototype.toString.apply({}) === "[Object object]" ------>返回true
Object.prototype.toString.apply(undefined) === "[Object Undefined]" ------>返回true