Object.prototype.isPrototypeOf()
The chain-walking counterpart to getPrototypeOf. It asks the same question as instanceof but against a prototype object directly, which is what you need when there is no constructor to name.
Demo
The array case is the one that teaches the method. It returns [true, true] — Array.prototype is its immediate prototype, AND Object.prototype is further up the same chain. isPrototypeOf walks the whole chain rather than checking one link, which is precisely how it differs from comparing getPrototypeOf. A plain object gives [true, false] because Array.prototype appears nowhere above it.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| object | any | yes | The object whose chain is searched. A primitive or a null always returns false rather than throwing. |
Return value
boolean — True if the receiver appears ANYWHERE in the argument prototype chain — not just as its immediate prototype.
Common patterns
if (basePrototype.isPrototypeOf(obj)) { }
if (obj instanceof Animal) { }
Object.getPrototypeOf(obj) === proto;
Examples
Pitfalls
[].isPrototypeOf(Array.prototype)
Array.prototype.isPrototypeOf([])
Object.prototype.isPrototypeOf([])
Object.getPrototypeOf([]) === Object.prototype
Object.create(null).isPrototypeOf({})
Object.prototype.isPrototypeOf.call(proto, obj)
Animal.isPrototypeOf(dog)
Animal.prototype.isPrototypeOf(dog)
When to use
- Testing ancestry against a prototype object you hold directly
- Code where no constructor function exists — objects built with Object.create
- Avoiding the Symbol.hasInstance indirection that instanceof allows
- There is a class or constructor → instanceof reads better
- You want the immediate prototype only → compare getPrototypeOf
- You want to know if a property exists → in, or Object.hasOwn
- The receiver may lack the method → borrow it with call
Notes
FAQ
instanceof whenever a constructor or class exists — it is shorter and more familiar. isPrototypeOf when you have the prototype object but no constructor, which happens with Object.create-based code and with cross-realm objects.
obj instanceof Animal; Animal.prototype.isPrototypeOf(obj); // the same check