bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/JavaScript/Working with Data
JavaScript•Working with Data

JavaScript Set Logic

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind JavaScript Set Logic?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ A = new Set(['a','b','c']);
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The intersection() Method
The union() Method
JavaScript Set Logic
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 :

Chrome 136Edge 136Firefox 129Safari 18.2Opera 120
Apr 2025Apr 2025Aug 2024Des 2024May 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);

Learn More

JavaScript Sets

JavaScript Set Methods

JavaScript Weak Sets

JavaScript Set Reference

JavaScript Maps

Previous

JavaScript Array Search

Next

JavaScript WeakMap