string 类型
- var a = "a"
- typeof a === "string"
number 类型
- let a = 111
- typeof a === "number"
function 类型
- var a = function(){}
- typeof a === "function"
undefined 类型
- var a =undefined
- typeof a === "undefined"
- a === undefined
Array 类型
- var a = []
- a instanceof Array
- Array.isArray(a)
null 类型
- var a =null
- a instanceof null
- a === null
RegExp 类型
- var a = /a/g
- a instanceof RegExp
Object 类型
- var a = {}
- typeof a === "object"
- a instanceof Object
注意: Object,Array,null,RegExp 都会判断为 Object, 请把 Object 放在最后一种类型判断
来源: http://www.bubuko.com/infodetail-2533976.html