← JavaScript

Sets – Basics

Creates a new Set, a built-in object that stores only unique values.

Understanding Sets – Basics in JavaScript

What it does: A Set only ever keeps one copy of each unique value. add() stores "red" in the colors Set. new Set() creates an empty Set ready to store unique values. add() inserts the given value into the Set. JavaScript requires a capital S: new Set(). JavaScript is case-sensitive, so 'add' must be lowercase. Adding a duplicate simply has no effect - it isn't an error. add() inserts 1 into the Set, if it isn't already there.

Common mistakes: 'Set' must start with a capital S, not lowercase. 'add' must be lowercase - a capital A causes an error.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 41–52) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does new Set() create a new Set object?
YesNo
Matches
let s = new set();
↓
Wrong - 'Set' must start with a capital S
Applying
Meanings
Term
new Set()
Meaning
Creates a new Set, a built-in object that stores only unique values.
Practice
let nums = new Set();
Testing
Gaps
let nums = Set();
Check Answer
Spots
1let s = new set();
2s.add(1);

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Giant Squid' badge — Nested Navigator, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does new Set() create a new Set object?
A. No
B. Yes ✓
new Set() creates an empty Set ready to store unique values.
2. Does add() add a value to a Set?
A. Yes ✓
B. No
add() inserts the given value into the Set.
3. Does a Set automatically remove duplicate values?
A. No
B. Yes ✓
A Set only ever stores one copy of each unique value.
4. Is 'set' with a lowercase s valid for creating a Set?
A. No ✓
B. Yes
JavaScript requires a capital S: new Set().
5. Must 'add' be written in lowercase?
A. Yes ✓
B. No
JavaScript is case-sensitive, so 'add' must be lowercase.

Match the Pairs

new Set() → Creates a new, empty Set
nums.add(1) → Adds the value 1 to the nums Set
Automatically removes duplicate values from a collection → Set
Inserts a value into a Set → colors.add("red")
let s = new set(); → Wrong - 'Set' must start with a capital S
s.Add(1); → Wrong - 'add' must start with a lowercase a

Key Term

new Set()
Creates a new Set, a built-in object that stores only unique values.

Fill in the Blanks

1. let nums = new Set();
Hint: Type the keyword used to create a new Set.
2. nums.add(1);
Hint: Type the method that adds a value to a Set.
3. let colors = new Set();
Hint: Type the keyword used to create a new Set.
4. colors.add("red");
Hint: Type the method that adds a value to a Set.
5. nums.add(2);
Hint: Type the method that adds a value to a Set.

Spot the Error

Question 1
A let s = new set();
B s.add(1);
C console.log(s);
Line A — 'Set' must start with a capital S, not lowercase.
Question 2
A let s2 = new Set();
B s2.Add(2);
C console.log(s2);
Line B — 'add' must be lowercase - a capital A causes an error.
Question 3
A let s3 = new Set();
B s3.add(3);
C s3.add(3);
Line C — This line is actually correct - adding a duplicate just has no effect.
Question 4
A let a = 1;
B let b = 2;
C let s5 = new set();
Line C — 'Set' must start with a capital S, not lowercase.
Question 5
A let s6 = new Set();
B s6.add(4);
C console.log(s6);
D s6.Add(5);
Line D — 'add' must be lowercase - a capital A causes an error.

Student with a class code? Join your class →