A quick-reference cheatsheet for checking every JavaScript type correctly — primitives, arrays, dates, maps, sets, and more.
Primitives
Use typeof for all primitives except null.
Loading editor...
null — the special case
typeof null returns "object" (a historic JS bug). Always use strict equality.
Loading editor...
Arrays — Array.isArray()
typeof [] returns "object", so you need Array.isArray.
Loading editor...
Functions
Loading editor...
Plain objects
Check typeof === "object" AND rule out null and arrays.
Loading editor...
Built-in objects — instanceof
Use instanceof for Date, Map, Set, RegExp, Promise, and Error.
Loading editor...
The universal tool — Object.prototype.toString
Returns an exact [object Type] tag for any value, including ones typeof and instanceof can't distinguish.
Loading editor...
Summary table
| What you want to check | Correct method |
|---|---|
string | typeof x === "string" |
number | typeof x === "number" |
boolean | typeof x === "boolean" |
undefined | typeof x === "undefined" |
bigint | typeof x === "bigint" |
symbol | typeof x === "symbol" |
null | x === null |
| Array | Array.isArray(x) |
| Function | typeof x === "function" |
| Plain object | x !== null && typeof x === "object" && !Array.isArray(x) |
| Date | x instanceof Date |
| Map | x instanceof Map |
| Set | x instanceof Set |
| RegExp | x instanceof RegExp |
| Any type precisely | Object.prototype.toString.call(x) |
For the full explanation of why these quirks exist, see Data Types & Type Checking.