typeof

Returns a string indicating the type of an operand.

Since ES1 Spec ↗

Syntax

typeof operand

Returns

string — One of `"undefined"`, `"boolean"`, `"number"`, `"bigint"`, `"string"`, `"symbol"`, `"function"`, or `"object"`.

Examples

console.log(typeof 42);
console.log(typeof "hi");
console.log(typeof true);
Output
number
string
boolean
console.log(typeof undefined);
console.log(typeof null);
console.log(typeof {});
Output
undefined
object
object
console.log(typeof function () {});
console.log(typeof Symbol());
console.log(typeof 10n);
Output
function
symbol
bigint

Notes

- `typeof null` is `"object"` — a long-standing language quirk. - `typeof` on an undeclared variable returns `"undefined"` without throwing, which makes it safe for existence checks. - Arrays report as `"object"`; use `Array.isArray()` to detect arrays.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also