# isObject
# Description
检查 value 是否为 Object 的 language type (opens new window) 。 (例如: arrays, functions, objects, regexes,new Number(0), 以及 new String(''))
# Params
Value
# Return
Boolean
# Code
function isObject(value) {
const type = typeof value
return value != null && (type === 'object' || type === 'function')
}
# Analyze
- 拿到
value的typeof值 type不为null并且type等于object或者function
# Remark
- 使用
new构造的string和number是object类型, Number 构造函数 MDN (opens new window) ,String 构造函数 MDN (opens new window) - typeof MDN (opens new window)
- ECMA Function (opens new window)
# Example
isObject({}) // => true
isObject([1, 2, 3]) // => true
isObject(Function) // => true
isObject(null) // => false
← isNumber isObjectLike →