JavaScript Set isDisjointFrom() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

set.isDisjointFrom(other) checks whether two Sets have nothing in common. It returns true when no value appears in both Sets, and false when at least one value is shared.

Two Sets that do not overlap are called disjoint. The method only answers true or false: it does not create a new Set and it does not change either Set. The argument must be a Set or a set-like object such as a Map.

Remember
a.isDisjointFrom(b)

no shared value     → true
one or more shared  → false

An empty Set is disjoint from every Set
Same as: a.intersection(b).size === 0
Returns a boolean, not a Set

Syntax

Call it on a Set and pass another Set. Use the boolean in an if statement.

JavaScript
const weekdays = new Set(["mon", "tue", "wed"]);
const weekend = new Set(["sat", "sun"]);

console.log(weekdays.isDisjointFrom(weekend));   // true
console.log(weekdays.isDisjointFrom(new Set(["wed", "thu"])));   // false
CallWhat it does
a.isDisjointFrom(b)true if a and b share no value.
!a.isDisjointFrom(b)true if they share at least one value (they overlap).
a.intersection(b).size === 0The same check, but it builds a whole new Set first.
a.isDisjointFrom(map)A Map works as the argument, and its keys are compared.

A standard JavaScript method (ES2025) on every Set, from Set.prototype. It works in current browsers and in Node.js 22 or newer. Siblings: add(), clear(), delete(), difference(), entries(), forEach(), has(), intersection(), isSubsetOf(), isSupersetOf(), keys(), symmetricDifference(), union(), values(), [Symbol.iterator]().

Library declarations
JavaScript
// ECMAScript 2025
Set.prototype.isDisjointFrom(other)

// other  : a Set, or a set-like object (needs size, has() and keys())
// returns: true or false
// throws : TypeError if other is not set-like (for example an array)

Parameters

ParameterDescription
otherRequired. A Set, or any set-like object: an object with a numeric size and the methods has() and keys(). A Map is set-like. An array is not, so convert it with new Set(array).

Return Value

Return ValueDescription
trueThe two Sets have no value in common.
falseAt least one value is in both Sets.
TypeError (thrown)other is not set-like, for example an array or a number.

JavaScript Examples

Example 1 — Check Whether Two Sets Overlap

Compare weekdays with the weekend, and then with a Set that shares one day.

JavaScript
const weekdays = new Set(["mon", "tue", "wed"]);
const weekend = new Set(["sat", "sun"]);
const midweek = new Set(["wed", "thu"]);

console.log("Weekdays vs weekend: " + weekdays.isDisjointFrom(weekend));
console.log("Weekdays vs midweek: " + weekdays.isDisjointFrom(midweek));
Try It Yourself

The Try It page first checks that Set.prototype.isDisjointFrom() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. No shared day. weekdays and weekend have no value in common, so the answer is true.
  2. One shared day. "wed" is in both weekdays and midweek, so the answer is false.
  3. Only a yes or no. The method does not tell you which value is shared. Use intersection() if you need to see it.

Example 2 — Empty Sets and a Map

See what happens with an empty Set and with the same Set. A Map can be the argument, and its keys are compared.

JavaScript
const nums = new Set([1, 2, 3]);

console.log("Empty Set: " + nums.isDisjointFrom(new Set()));
console.log("Itself: " + nums.isDisjointFrom(nums));

const lookup = new Map([[3, "three"], [9, "nine"]]);
console.log("Map with key 3: " + nums.isDisjointFrom(lookup));

const other = new Map([[7, "seven"]]);
console.log("Map without shared key: " + nums.isDisjointFrom(other));
Try It Yourself

The Try It page first checks that Set.prototype.isDisjointFrom() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. Empty Set. Nothing in an empty Set can be shared, so the answer is true.
  2. Itself. A Set that has values shares all of them with itself, so the answer is false.
  3. Map keys. The Map is compared by its keys. 3 is a key and is also in nums, so the first Map gives false. The second Map has only key 7, so the answer is true.

Example 3 — Check Permissions

A practical use: find out whether a user has any of the blocked permissions.

JavaScript
const blocked = new Set(["delete", "admin"]);

const ann = new Set(["read", "write"]);
const bob = new Set(["read", "delete"]);

function check(name, permissions) {
  if (permissions.isDisjointFrom(blocked)) {
    console.log(name + ": allowed");
  } else {
    console.log(name + ": blocked");
  }
}

check("Ann", ann);
check("Bob", bob);
Try It Yourself

The Try It page first checks that Set.prototype.isDisjointFrom() exists, because it is new in ES2025. In an older browser it prints a short explanation and the output above. In current browsers and in Node.js 22 or newer, it runs the code for real.

How It Works

  1. A list to avoid. blocked holds the permissions that must not be given.
  2. Ann. She has read and write. None of them is blocked, so the two Sets are disjoint and she is allowed.
  3. Bob. He has delete, which is also in blocked. The Sets overlap, so the answer is false and he is blocked.

Browser & Runtime Support

Set.prototype.isDisjointFrom() is one of the new Set methods added in ES2025. It works in current browsers and in Node.js 22 or newer, but not in older versions.

✓ Newer · ES2025

set.isDisjointFrom()

Supported in Chrome 122+, Edge 122+, Firefox 127+, Safari 17+, Opera 108+ and Node.js 22+. Internet Explorer never got it.

ES2025 Standard since
Google Chrome 122+ · Desktop & Mobile
Full support
Microsoft Edge 122+ · Chromium based
Full support
Mozilla Firefox 127+ · Desktop & Mobile
Full support
Apple Safari 17+ · macOS & iOS
Full support
Opera 108+ · Chromium based
Full support
Samsung Internet 26+ · Android
Supported
Android WebView 122+ · Chromium based
Supported
Node.js 22+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
set.isDisjointFrom() Recent browsers

Bottom line: Check support with typeof Set.prototype.isDisjointFrom === "function". For older browsers, the same result can be made with the spread syntax and filter(), or with a loop.

Frequently Asked Questions

It checks that two Sets have no value in common. It returns true when they do not overlap and false when at least one value appears in both.
Yes. An empty Set has no values, so nothing can be shared, and the answer is always true.
isDisjointFrom() only returns true or false. intersection() builds a new Set with the shared values. Use isDisjointFrom() when you only need the yes or no answer.
No. The argument must be a Set or a set-like object such as a Map. An array throws a TypeError. Use new Set(array) to convert it first.
Use [...a].every((x) => !b.has(x)). It returns true when no value of a is found in b, which is the same answer.

Next: isSubsetOf()

Learn how to check that every value of one Set is also inside another Set.

isSubsetOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful