Skip to content

typeof

In JavaScript, the typeof keyword is a unary operator that returns a string naming the type of its operand’s value. The result is one of eight strings: "undefined", "boolean", "number", "bigint", "string", "symbol", "function", or "object".

Most primitive types, such as string or bigint, have a matching result. Functions, including classes, are objects, but typeof reports them as "function". Arrays, dates, and other objects all give "object", so telling them apart takes Array.isArray() or instanceof.

The value null also gives "object", even though it’s a primitive. This historical bug dates from the first JavaScript implementation and stays for compatibility, so a check for objects needs value !== null too.

An undeclared variable gives "undefined" instead of throwing a ReferenceError. A let, const, or class binding read before its declaration still throws, because of the temporal dead zone. The typeof operator binds tighter than binary operators, so typeof (a + b) needs the parentheses.

JavaScript typeof Keyword Syntax

The typeof operator takes a single operand:

Language: JavaScript Syntax
typeof <operand>

JavaScript typeof Keyword Examples

The typeof operator returns a string that names a value’s type:

Language: JavaScript
> typeof 42
'number'
> typeof "Ada"
'string'
> typeof 10n
'bigint'

> typeof [1, 2, 3]
'object'
> typeof null
'object'
> typeof class User {}
'function'

> typeof notDeclaredAnywhere
'undefined'

The array and null both report "object", while the class reports "function". Checking an undeclared name doesn’t throw.

JavaScript typeof Keyword Use Cases

  • Checking whether an argument is a string, number, or function before using it
  • Detecting whether a global such as window exists in the current host
  • Telling primitives apart from objects, with an extra check for null
  • Narrowing a value’s type in functions that accept several types

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026