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://blog.51cto.com/13661873/2089344
时间: 2024-11-06 03:44:32