JavaScript instanceof

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

value instanceof Constructor is true when Constructor.prototype is in value’s prototype chain. Useful for class instances and built-ins like Date or Array (prefer Array.isArray for arrays).

JavaScript Syntax

JavaScript
console.log([] instanceof Array);
console.log(new Date() instanceof Date);
console.log({} instanceof Array);
Try it Editor

How It Works

  1. Arrays. [] inherits from Array.prototype.
  2. Plain objects. Not Array instances.

Examples

Example 1 — Custom classes

Works with class constructors.

JavaScript
class Dog {}
console.log(new Dog() instanceof Dog);
Try it Editor

How It Works

  1. Instance links to Dog.prototype.

Example 2 — null and primitives

null/undefined throw or are false safely with care.

JavaScript
console.log(null instanceof Object);
Try it Editor

How It Works

  1. null is not an object instance.

Example 3 — Primitives

Numbers are not Number objects.

JavaScript
console.log(3 instanceof Number);
console.log(Object(3) instanceof Number);
Try it Editor

How It Works

  1. Bare 3 is a primitive.
  2. Object(3) boxes it.

Frequently Asked Questions

typeof works on primitives; instanceof checks prototype identity for objects.

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