TypeOf Operator
Last updated
Last updated
The typeof
operator returns a string indicating the type of the operand's value.
The following table summarizes the possible return values of typeof
. For more information about types and primitives, see also the page.
"undefined"
"boolean"
"number"
"bigint"
"string"
"symbol"
"function"
Any other object
"object"
This list of values is exhaustive. No spec-compliant engines are reported to produce (or had historically produced) values other than those listed.
Copy to Clipboard
Copy to Clipboard
"object"
()
(implements [[Call]] in ECMA-262 terms; are functions as well)
In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0
. null
was represented as the NULL pointer (0x00
in most platforms). Consequently, null
had 0
as type tag, hence the typeof
return value "object"
. ()
A fix was proposed for ECMAScript (via an opt-in), but . It would have resulted in typeof null === "null"
.
All constructor functions called with will return non-primitives ("object"
or "function"
). Most return objects, with the notable exception being , which returns a function.