Type Checking Quick Reference

The right way to check every JavaScript type — typeof for primitives, Array.isArray for arrays, instanceof for built-ins, and Object.prototype.toString for everything else.

4 min read
JavaScript
Fundamentals
Types
typeof

TABLE OF CONTENTS

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 checkCorrect method
stringtypeof x === "string"
numbertypeof x === "number"
booleantypeof x === "boolean"
undefinedtypeof x === "undefined"
biginttypeof x === "bigint"
symboltypeof x === "symbol"
nullx === null
ArrayArray.isArray(x)
Functiontypeof x === "function"
Plain objectx !== null && typeof x === "object" && !Array.isArray(x)
Datex instanceof Date
Mapx instanceof Map
Setx instanceof Set
RegExpx instanceof RegExp
Any type preciselyObject.prototype.toString.call(x)

For the full explanation of why these quirks exist, see Data Types & Type Checking.


Let's Connect

© 2026 Naveen Karthik // Built with React & MUI