Dev Helpers

JavaScript / Classes and protocols

Identify a branded instance with instanceof

Dev Helpers · August 30, 2025

An instanceof check tests a constructor relationship. Deserialized records do not automatically regain the class prototype.

Worked example

class Invoice {}
const value = new Invoice();
console.log(value instanceof Invoice, {} instanceof Invoice);

Result

true false

Implementation notes

A constructor check can change across frames or separately loaded copies of a package. An explicit discriminant is often a better identity for exchanged data.

Try it yourself

Compare an instance with its JSON round trip.

Open the JavaScript example →

Editorial date August 30, 2025 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.