# .isDisjointFrom()

> The `.isDisjointFrom()` JS method checks whether the current `Set` object has no elements in common with the `Set` object provided as an argument.

## How do I check if two Sets share no values with isDisjointFrom()?

The method that checks whether the `Set` object on which it's called has no elements in common with the `Set` object passed as an argument. It returns `true` if they are disjoint, meaning they have no common elements and `false` if at least one element is shared.

- Topic: Set
- Type: method
- Browser support: Chrome 122+, Chrome Android 122+, Edge 122+, Firefox 127+, Firefox Android 127+, Safari 17+, Safari iOS 17+

## Example

Wrong:

```js
if (a.isDisjointFrom(b)) {
  warn('Sets overlap');
}
```

Right:

```js
if (!a.isDisjointFrom(b)) {
  warn('Sets overlap');
}
```

`isDisjointFrom()` returns `true` when there is no overlap, so the warning needs the negation.

## Common mistakes

- Reading `isDisjointFrom()` backwards and treating `true` as 'they overlap'.

## Key points

- The argument is a `Set` or set-like object with `size`, `has()` and `keys()`, not a plain array.
- The result is read correctly: `true` means the sets have no values in common.
- Code for older browsers falls back to `![...a].some((x) => b.has(x))`.

## Interview questions

### Is `isDisjointFrom()` better than `intersection().size === 0`?

Usually yes. It can stop at the first shared value and does not build a new set.

### What does `isDisjointFrom()` return for an empty Set?

`true`. An empty set shares no values with any set.

## Related cards

- [.intersection()](https://wonderium.dev/js/set-intersection.md)
- [.isSupersetOf()](https://wonderium.dev/js/set-is-superset-of.md)
- [Set.has()](https://wonderium.dev/js/set-has.md)
- [Array.some()](https://wonderium.dev/js/array-some.md)
- [Set](https://wonderium.dev/js/set.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/set-is-disjoint-from
- Last updated: 2026-11-25
