Not What It Is, But Where It Belongs: Rethinking instanceof in JavaScript
instanceof doesnât check what an object is, but whether it belongs to a constructorâs prototype chain, revealing that JavaScript defines objects through relationships rather than origin.
Thereâs a quiet assumption we often carry when we write code:
That objects know what they are.
That somewhere inside them is a labelâ
a definitive identityâthat tells us:
âThis is an Arrayâ
âThis is a Personâ
âThis is a Dateâ
And when we reach for instanceof, it feels like weâre asking that question directly.
But JavaScript doesnât answer it the way we expect.
Because itâs not asking what something is.
Itâs asking something else entirely.
A Question About Belonging
When you write:
obj instanceof Constructor
It looks like a type check.
But itâs not checking identity.
Itâs checking relationship.
More specifically:
Does this object belong to the prototype chain of that constructor?
This is not about creation.
Itâs about connection.
Following the Chain
Every object in JavaScript exists within a chain.
Not a hierarchy in the traditional senseâ
but a linked structure of prototypes.
An object points to a prototype.
That prototype points to another.
And so on, until the chain ends.
When instanceof runs, it walks this chain.
Step by step.
Looking for one specific thing:
The prototype of the constructor you provided.
If it finds it, the answer is true.
If it doesnât, the answer is false.
Thatâs all.
The Illusion of Origin
Itâs tempting to think:
âIf an object was created using a constructor, then it must be an instance of it.â
And often, thatâs true.
But only because the constructor sets up the prototype chain that way.
The connection feels like originâ
but itâs really just structure.
And structure can be changed.
When Expectations Break
Because this system is based on prototypes, not creation, it allows for something unusual.
You can take an objectâ
one that has nothing to do with a constructorâ
and link it into that constructorâs prototype chain.
And suddenly, instanceof will return true.
Not because the object was created differently.
But because its position in the chain has changed.
The result feels incorrect.
But the mechanism is working exactly as designed.
Identity Is Not Enough
This reveals something deeper:
JavaScript does not define objects by where they came from.
It defines them by how they are connected.
Two objects can look identical.
Behave identically.
Hold the same values.
And yet, instanceof may treat them differentlyâ
because their prototype chains are not the same.
Not structurally similar.
Exactly the same.
A Boundary You Donât Always See
This becomes even more apparent when you cross environments.
An array created in one contextâ
say, an iframeâ
is not considered an instance of Array in another.
Even though everything about it appears identical.
Because under the surface:
They do not share the same prototype reference.
The structure matches.
The identity does not.
And for instanceof, identity is everything.
When the Rules Can Be Rewritten
Thereâs an even stranger possibility.
You can redefine how instanceof behaves.
Override its logic entirely.
Make it return true or false based on conditions you control.
At that point, the question:
âIs this an instance of that?â
Stops being objective.
And becomes something you define.
Which tells you something important:
Even this mechanism is not absolute.
It is flexible.
By design.
A Shift in Understanding
Once you see how instanceof works, your thinking begins to change.
You stop asking:
âWhat is this object?â
And start asking:
âWhat is this object connected to?â
That shift may seem smallâ
but it aligns your thinking with how JavaScript actually operates.
Not through rigid identityâ
but through relationships.
The Shape Beneath the Surface
In many languages, types are declarations.
In JavaScript, they are emergent.
They arise from how objects are linked.
From how prototypes are arranged.
From how structure is composed.
instanceof is simply a way of observing that structure.
Not defining it.
A Final Reflection
instanceof doesnât tell you what something is.
It tells you where it lives.
Which chain it belongs to.
Which structure it participates in.
Which relationships define it.
And once you understand that,
you begin to see objects differently.
Not as isolated entitiesâ
but as points within a connected system.
Defined not by originâ
but by association.
And in that system, identity is not declared.
It is inherited.