# 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 →