CKTIS / JavaScript
Set.prototype.isDisjointFrom — testing whether sets are disjoint
Set.prototype.isDisjointFrom checks whether a set has no elements in common with another set or a set-like object. It returns a Boolean rather than creating a new set.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
set.isDisjointFrom(other)set.isDisjointFrom(other) returns true when the sets share no elements and false when it finds any shared element. For ordinary Set objects, an empty set is disjoint from every set, including an empty one. The method creates no result set and does not itself modify its operands.
The receiver set must be a genuine Set object; merely providing similar methods is insufficient. The argument other may be set-like: it must expose a valid size and callable has and keys methods. A Set or Map qualifies; for a Map, its keys are checked. Being iterable alone is insufficient: a plain array is not a valid argument; use new Set(array) instead.
For ordinary sets, comparison follows SameValueZero: NaN matches NaN, and +0 matches -0; objects are compared by identity, not contents. The method compares the internal element count of set with the size obtained from other.size; it does not read the public set.size property. If that internal count is less than or equal to the size of other, the method traverses set and calls other.has; otherwise, it obtains elements through other.keys. It stops upon finding a shared element. Custom getters or methods on other can have side effects or throw exceptions, so avoid mutating the sets during the check.
The method belongs to ECMAScript 2025, not Web APIs. The language specification does not establish support in a particular browser version. Before using it in the target environment, check typeof Set.prototype.isDisjointFrom === "function"; having Node 24 in a repository does not prove browser support.
Examples
const selected = new Set([2, 4]);
const available = new Set([1, 3]);
const reserved = new Set([4, 6]);
console.log(selected.isDisjointFrom(available));
console.log(selected.isDisjointFrom(reserved));
console.log(selected.isDisjointFrom(new Set()));Result
true false true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.