node.isSameNode(otherNode) returns true when both values refer to the exact same node object. MDN calls it a legacy alias for ===(MDN).
Status: Baseline Widely available (since August 2016) — not Deprecated, Experimental, or Non-standard. Prefer === in new code (MDN: there is no need to use isSameNode()).
Remember
a.isSameNode(b) ≡ a === b
→ true if same object
→ false if different objects — or if b is null
a === b → same object? (prefer this)
a.isSameNode(b) → same object? (legacy alias)
a.isEqualNode(b) → equal structure?
Pass another node (or null) and read the boolean — or just use ===.
Get two node references to compare.
Prefer a === b for identity (MDN).
Or call a.isSameNode(b) — same result as ===.
Use isEqualNode when you care about structure, not identity.
Piece
Required?
Role
node
Yes
Node calling the method
otherNode
Yes (may be null)
Node to test against
Return
—
true if strictly the same object
Pseudocode
Pseudocode
// isSameNode is a legacy alias for ===
return a === otherNode
// which means:
if a and otherNode are the exact same object:
return true
else:
return false // includes otherNode === null
Reference
Cheat Sheet
Keep these identity facts handy.
Topic
Detail
Syntax
node.isSameNode(otherNode)
Returns
boolean
Meaning
Legacy alias for === (MDN)
New code
Prefer a === b
null
false (not the same object)
vs isEqualNode
Identity vs structure
Standard
Baseline Widely available (since August 2016)
Try it
Live Preview
Compare three divs (MDN-style): matching content is not the same object.
Nodes
This is the first element.
This is the second element.
This is the first element.
Browser demo of Node.isSameNode() — identity, not structure.
Result
Choose a pair, then Compare…
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Matching Content ≠ Same Node
MDN’s three-div demo: twins look alike but are different objects.
Node.isSameNode() is marked Baseline Widely available on MDN (since August 2016).
✓ Baseline · Widely available
Node.isSameNode()
Legacy alias for === — tests whether two references are the same node object. Prefer === in new code. Not Deprecated, Experimental, or Non-standard.
100%Widely available
Google ChromeYes (Baseline)
Yes
Microsoft EdgeYes (Baseline)
Yes
Mozilla FirefoxYes (Baseline)
Yes
Apple SafariYes (Baseline)
Yes
OperaYes (Baseline)
Yes
Internet ExplorerSupported (legacy)
Yes
isSameNode()Excellent
Bottom line: Safe to encounter in older code. Write === for identity. See the MDN isSameNode reference.
Analysis
Performance Notes
Approach
Cost
Best for
=== / isSameNode
O(1)
“Is this the same node?”
isEqualNode small trees
Cheap
Typical UI nodes
isEqualNode huge subtrees
Walks the tree
Avoid when you only need identity
Identity is a reference check — use it in hot paths. Reach for isEqualNode only when structure matters.
Remember
Key Takeaways
Identity: same object in memory, not “looks alike.”
Prefer ===: MDN legacy alias — write idiomatic JS.
Twins & clones: equal ≠ same — use isEqualNode for structure.
null → false: never the same node object.
One line:isSameNode is a legacy === — ask “same object?” not “looks the same?”
Frequently Asked Questions
It returns true if both arguments refer to the exact same node object. MDN describes it as a legacy alias for the === strict equality operator.
No. MDN marks Node.isSameNode() as Baseline Widely available (since August 2016). It is not Deprecated, Experimental, or Non-standard — but MDN notes you do not need it and should prefer === in new code.
Prefer ===. It is clearer, idiomatic JavaScript, and does the same identity check. Keep isSameNode in mind when reading older DOM code.
isSameNode / === ask “same object?” isEqualNode asks “same structure and defining data?” Matching markup can be equal without being the same node.
The parameter is required in the signature but may be null. Comparing to null is not the same object, so the result is false (same idea as node === null).
No. Separate elements in the document are different objects even if their contents match — isSameNode is false while isEqualNode may be true.