← JavaScript

Maps – Basics

Creates a new Map, a built-in object that stores key-value pairs.

Understanding Maps – Basics in JavaScript

What it does: get() looks up the value stored for the "Sam" key. set() stores 30 under the key "Tom" in the ages Map. new Map() creates an empty Map ready to store key-value pairs. set() stores a value under the given key in the Map. JavaScript requires a capital M: new Map(). JavaScript is case-sensitive, so 'set' must be lowercase. set() takes the key first, then the value to store. set() adds this key-value pair to the Map.

Common mistakes: 'Map' must start with a capital M, not lowercase. 'set' must be lowercase - a capital S 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 Map() create a new Map object?
YesNo
Matches
let m = new map();
↓
Wrong - 'Map' must start with a capital M
Applying
Meanings
Term
new Map()
Meaning
Creates a new Map, a built-in object that stores key-value pairs.
Practice
let scores = new Map();
Testing
Gaps
let scores = Map();
Check Answer
Spots
1let m = new map();
2m.set("a", 1);

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

The 'Dumbo Octopus' badge — Module Maker, 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 Map() create a new Map object?
A. Yes ✓
B. No
new Map() creates an empty Map ready to store key-value pairs.
2. Does set() add a key-value pair to a Map?
A. No
B. Yes ✓
set() stores a value under the given key in the Map.
3. Does get() read a value from a Map using its key?
A. Yes ✓
B. No
get() looks up and returns the value stored for that key.
4. Is 'map' with a lowercase m valid for creating a Map?
A. Yes
B. No ✓
JavaScript requires a capital M: new Map().
5. Must 'set' be written in lowercase?
A. Yes ✓
B. No
JavaScript is case-sensitive, so 'set' must be lowercase.

Match the Pairs

new Map() → Creates a new, empty Map
scores.set("Sam", 90) → Stores 90 under the key "Sam" in the scores Map
Reads the value stored under a given key → scores.get("Sam")
Adds a new key-value pair to a Map → ages.set("Tom", 30)
let m = new map(); → Wrong - 'Map' must start with a capital M
m.Set("a", 1); → Wrong - 'set' must start with a lowercase s

Key Term

new Map()
Creates a new Map, a built-in object that stores key-value pairs.

Fill in the Blanks

1. let scores = new Map();
Hint: Type the keyword used to create a new Map.
2. scores.set("Sam", 90);
Hint: Type the method that adds a key-value pair to a Map.
3. console.log(scores.get("Sam"));
Hint: Type the method that reads a value from a Map by its key.
4. let ages = new Map();
Hint: Type the keyword used to create a new Map.
5. ages.set("Tom", 30);
Hint: Type the method that adds a key-value pair to a Map.

Spot the Error

Question 1
A let m = new map();
B m.set("a", 1);
C console.log(m);
Line A — 'Map' must start with a capital M, not lowercase.
Question 2
A let m2 = new Map();
B m2.Set("b", 2);
C console.log(m2);
Line B — 'set' must be lowercase - a capital S causes an error.
Question 3
A let m3 = new Map();
B m3.set("c", 3);
C console.log(m3.Get("c"));
Line C — 'get' must be lowercase - a capital G causes an error.
Question 4
A let a = 1;
B let b = 2;
C let m5 = new map();
Line C — 'Map' must start with a capital M, not lowercase.
Question 5
A let m6 = new Map();
B m6.set("d", 4);
C console.log(m6);
D m6.Set("e", 5);
Line D — 'set' must be lowercase - a capital S causes an error.

Student with a class code? Join your class →