Back to JavaScript Notes
Topic #72

JS Set Logic

Set logic — union, intersection, difference — solves overlap questions between collections. It is set theory applied to real data.

Col 1
Logic Set Methods In JavaScript 2025, 7 new logical methods were added to the Set object: union() difference() intersection() isDisjointFrom() isSubsetOf() isSupersetOf() symmetricDifference()

Browser Support

Set Logic is an ECMAScript 2025 feature.

JavaScript 2025 is fully supported in all modern browsers since May 2025:


The union() Method

The union() method returns the union of two sets.

The union() method returns a new set containing the elements which are in this set, or in the argument set, or in both:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

const C = A.union(B);

The intersection() Method

The intersection() method returns the intersection of two sets.

The intersection() method returns a new set containing the elements which are in this set and in the argument set:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

const C = A.intersection(B);

The difference() Method

The difference() method returns the difference between two sets.

The difference() method returns a new set containing elements which are in this set but not in the argument set:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

const C = A.difference(B);

The symmetricDifference() Method

The symmetricDifference() method returns the symmetric difference between to sets.

The symmetricDifference() method returns a new set containing elements which are in this set or in the argument set, but not in both:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

const C = A.symmetricDifference(B);

The isSubsetOf() Method

The isSubsetOf() method returns true if all elements in this set is also elements in the argument set:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

let answer = A.isSubsetOf(B);

The isSupersetOf() Method

The isSupersetOf() method returns true if all elements in the argument set are also in this set:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

let answer = A.isSupersetOf(B);

The isDisjointFrom() Method

The isDisjointFrom() method returns true if this set has no elements in common with the argument set:

Example

const A = new Set(['a','b','c']);

const B = new Set(['b','c','d']);

let answer = A.isDisjointFrom(B);

Note: Learn More: JavaScript Sets JavaScript Set Methods JavaScript Weak Sets JavaScript Set Reference JavaScript Maps

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS Set Logic – FAQs

Quick answers about learning JS Set Logic in JavaScript.

This free note from Coding Now Tech Institute explains JS Set Logic in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JS Set Logic, is 100% free with no signup required.
With focused practice, most students grasp JS Set Logic in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now