Skip to content
UniCircle
EasyConceptualData types

The typeof operator and its surprises

Question JS-TYP-003

What does typeof return for each kind of value? Which results surprise people, and how do you reliably check for an array or null?

Show the explanation

Model answer. typeof returns a string:

  • 'string', 'number', 'bigint', 'boolean', 'symbol', 'undefined' for those primitives
  • 'function' for functions (including classes)
  • 'object' for everything else

The surprises:

  • typeof null === 'object' (a bug from the first version of the language)
  • typeof [] === 'object', because arrays are objects
  • typeof NaN === 'number'

Reliable checks:

JavaScript
Array.isArray(value);          // arrays
value === null;                // null
Number.isNaN(value);           // NaN (unlike the global isNaN, no coercion)
value instanceof Date;         // a specific class

typeof is also the only safe way to test a name that may not be declared at all: typeof someGlobal === 'undefined' does not throw.

Original UniCircle question. Last reviewed 22 Oct 2026.