1. 通过typeof来判断
2. 通过instanceof来判断 或 通过constructor来判断
3. null直接全等判断即可
4. 万能判断方式:Object.prototype.toString.call()
1. 通过typeof来判断
typeof undefined // undefined
typeof 1 // number
typeof '1' // string
typeof true // boolean
typeof function() {} // function
typeof Symbol() // symbol
// 以下类型需要别的方式判断
typeof null // object
typeof {} // object
typeof [] // object
2. 通过instanceof来判断 或 通过constructor来判断
// 以下这个不准确,因为instanceof会去找原型链。而引用类型的__proto__最终都会指向Object.prototype。
obj instanceof Object // true
[] instanceof Object // true
new Date() instanceof Object // true
new RegExp() instanceof Object // true
// 判断对象更好的方式:
obj.constructor === Object // true
// 判断数组
[] instanceof Array // true
[].constructor === Array // true
// 判断日期对象
new Date() instanceof Date // true
new Date().constructor &