JavaScript typeof

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

The typeof operator returns a string naming the type of its operand: "string", "number", "boolean", "undefined", "object", "function", or "symbol" / "bigint".

JavaScript Syntax

JavaScript
console.log(typeof "hi");
console.log(typeof 3);
console.log(typeof true);
console.log(typeof undefined);
Try it Editor

How It Works

  1. Strings and numbers. Everyday primitives.
  2. undefined. Declared but not assigned, or missing args.

Examples

Example 1 — typeof null is "object"

A long-standing language quirk.

JavaScript
console.log(typeof null);
Try it Editor

How It Works

  1. null is not a real object.
  2. Check null with value === null.

Example 2 — Arrays are "object"

Use Array.isArray for lists.

JavaScript
console.log(typeof []);
console.log(Array.isArray([]));
Try it Editor

How It Works

  1. typeof cannot tell arrays from objects.
  2. Array.isArray is the right check.

Example 3 — Functions

Functions have their own typeof result.

JavaScript
console.log(typeof function () {});
Try it Editor

How It Works

  1. Callables report "function".

Frequently Asked Questions

A string such as "number" or "string".
Use Array.isArray(value), not typeof.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful