Map and Set
In short: a Map pairs keys with values, like an object, but any
value can be a key and keys are never converted to strings. A Set keeps
each value exactly once — adding a duplicate does nothing. Both remember
insertion order and use .size, not .length, plus their own methods
(get/set/has for Map; add/has for Set) rather than square
brackets. Use a Map when you need to look something up by key; use a Set
when you only need to know "is it in here?" with no duplicates.

Count plays with a Map
A Map's get/set/has work by key, and the key can be anything — here
it's a song title:
get on a missing key returns undefined rather than throwing, so a
counting pattern usually reads the current count first and falls back to a
starting value:
This prints [["Blue Hour", 2], ["Red Dawn", 1]] — Blue Hour played twice,
in the order each title was first seen.
A song finishes
"Blue Hour" ends. Read its current count:
plays.get("Blue Hour")is 3.
Keep a liked-songs list with no duplicates
A Set stores values, not pairs, and each value can appear only once:
The second add is silently ignored — size is still 1. The most common
Set trick removes duplicates from an array while keeping first-seen order:
This prints ["Blue Hour", "Red Dawn"] — the repeated "Blue Hour" at the
end collapses away.
The trap: a number key and its string look-alike
Object keys are always converted to strings, but Map keys are not — a number key and a string that looks the same are two different keys:
This prints undefined, not "one" — 1 (the number) and "1" (the
string) are separate keys in a Map, exactly the distinction that Data
Types warned about. Treating a Map like a plain object,
m["Blue Hour"], does not read its entries at all; always use get and
set.
Quick practice
What is new Set(["a", "b", "a"]).size?
After const m = new Map(); m.set("Blue Hour", 3);, what is m.get("Blue Hour")?
After const m = new Map(); m.set(1, "one");, what is m.get("1")?
What is [...new Set([3, 1, 3, 2, 1])]?
You need to know whether a listener has already liked a song, with no duplicates. Which fits best?
🎯 Your turn
For a listening history ["Blue Hour", "Red Dawn", "Blue Hour"], explain
how you would get the list of distinct songs and how you would count plays
per song, naming the collection for each and why.
Write your explanation and submit it — there's no code to run here, just your reasoning.
