The ECMAScript specification identifies these language data types:
6.1.1 The Undefined Type
6.1.2 The Null Type
6.1.3 The Boolean Type
6.1.4 The String Type
6.1.5 The Symbol Type
6.1.6 Numeric Types
6.1.6.1 The Number Type
6.1.6.2 The BigInt Type
6.1.7 The Object Type
For historical reasons the typeof
operator is not consistent with this categorisation in two cases:
typeof null == "object"
: this is unfortunate, but something we have to live with.
typeof
of a function object evaluates to "function", even though according to the specification it has as data type Object.
Another operator -- instanceof
-- can be used to know whether an object inherits from a certain prototype. For instance, [1,2] instanceof Array
will evaluate to true.
One way to determine whether a value is an object, is to use the Object
function:
if (Object(value) === value) // then it is an object; i.e., a non-primitive
typeof
is an operator and not a function, so the parentheses in your code are not necessary - you could simply use the syntaxtypeof null
.(typeof +(\w+) +={2,3} +"object")
to ->($2 && $1)
in order to fix this issue anywhere it may exist. This will turntypeof arg === "object"
into(arg && typeof arg === "object")