Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The typeof operator returns a string indicating the type of the operand's value.
An expression representing the object or primitive whose type is to be returned.
The following table summarizes the possible return values of typeof. For more information about types and primitives, see also the JavaScript data structure page.
| Undefined | "undefined" |
| Null | "object" (reason) |
| Boolean | "boolean" |
| Number | "number" |
| BigInt | "bigint" |
| String | "string" |
| Symbol | "symbol" |
| Function (implements [[Call]] in ECMA-262 terms; classes are functions as well) | "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.
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". (reference)
A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === "null".
All constructor functions called with new will return non-primitives ("object" or "function"). Most return objects, with the notable exception being Function, which returns a function.
The typeof operator has higher precedence than binary operators like addition (+). Therefore, parentheses are needed to evaluate the type of an addition result.
typeof works with undeclared identifiers, returning "undefined" instead of throwing an error.
However, using typeof on lexical declarations (let const, using await using, and class) in the same block before the place of declaration will throw a ReferenceError. Block scoped variables are in a temporal dead zone from the start of the block until the initialization is processed, during which it will throw an error if accessed.
See typeof operator and undefined for more details.
All current browsers expose a non-standard host object document.all with type undefined.
Although document.all is also falsy and loosely equal to undefined, it is not undefined. The case of document.all having type "undefined" is classified in the web standards as a "willful violation" of the original ECMAScript standard for web compatibility.
typeof is very useful, but it's not as versatile as might be required. For example, typeof [] is "object", as well as typeof new Date(), typeof /abc/, etc.
For greater specificity in checking types, here we present a custom type(value) function, which mostly mimics the behavior of typeof, but for non-primitives (i.e., objects and functions), it returns a more granular type name where possible.
For checking potentially non-existent variables that would otherwise throw a ReferenceError, use typeof nonExistentVar === "undefined" because this behavior cannot be mimicked with custom code.
| ECMAScript® 2027 Language Specification # sec-typeof-operator |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jan 8, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.