You've been doing Set math by hand. JavaScript finally shipped .union(), .intersection(), and friends.
Set has always been missing its obvious operations. ES2025 adds `.union()`, `.intersection()`, `.difference()`, `.symmetricDifference()`, and three boolean predicates — native methods that used to require four lines of spread syntax each.

You've written some version of this:
It works. It's also four lines of manual iteration for operations any set-theory textbook covers in a sentence. JavaScript's Set shipped in ES6 — ten years ago — but the methods that make sets actually useful didn't come with it.
ES2025 added them. All of them.
Every new Set method takes another set-like object — a Set, a Map, or anything with a size property and a has method — and returns a new Set without modifying either input.
.union(other) — all elements from both sets:
.intersection(other) — only elements present in both:
.difference(other) — elements in this that are not in other:
.symmetricDifference(other) — elements in exactly one of the two sets:
These four cover the standard set algebra you reach for most often. The other three are boolean predicates:
.isSubsetOf(other) — true if every element of this is in other:
.isSupersetOf(other) — true if every element of other is in this:
.isDisjointFrom(other) — true if the sets share no elements at all:
Runs right in your browser — poke at it and watch the concept react live.
The operations pay for themselves quickly when you're comparing sets of strings:
Or computing which tags changed between two versions of a document:
Before, each of those lines was a three-liner. Now each is one method call that reads exactly like what it computes.
Each method accepts any set-like object — not just Set instances. The spec defines set-like as any object with a numeric size property, a has(key) method, and a keys() method returning an iterator.
This means you can pass a Map as the argument and it works using the map's keys:
It also means you can build custom data structures that interoperate with the native methods without converting to a plain Set first — anything implementing the three-property contract is compatible.
TypeScript added the full method signatures in version 5.5 under the ES2025 lib. If your tsconfig.json targets an earlier version, you'll see type errors. The fix is adding "ES2025" (or the more specific "ES2025.Collection") to your lib array:
The algebra methods return Set<T> and the predicates return boolean. No type assertions or manual casting needed.
All seven methods are Baseline 2025: Chrome 122, Firefox 127, Safari 17.4, Node.js 22. Any environment targeting browsers from the last year ships these with no polyfill and no build step.
If you need to support older targets, a shim is a few dozen lines — but every major browser in active use today already has them natively.
Think it clicked? Take the 6-question quiz →
Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.
Search your codebase for filter(x => otherSet.has(x)) or new Set([...a, ...b]). Each one is a native Set method written by hand.
The new methods aren't just shorter — they're clearer. .difference() names the operation. A spread with a filter describes the implementation. When both are available, the one that names the operation wins: it reads faster, it refactors cleaner, and it signals intent to the next person in the file. The only reason to reach for the manual version now is a polyfill budget you almost certainly don't have.
Thanks for reading! Let's stay connected:
- ⭐ GitHub — follow me and star the projects: github.com/parsajiravand
- 💬 Discord — join the frontend best-practices community: discord.gg/d9KRhuAwQ
- 📸 Instagram — frontend best practices, daily: @bestpractice___
- 💼 LinkedIn — linkedin.com/in/parsa-jiravand
- ✉️ Email (work & contract inquiries): bestpractice2026@gmail.com
Originally published on dev.to