Advanced JavaScript / Map & Set
Map & Set
A Map pairs any key with a value; a Set holds only unique values.
`Map` is like an object, but keys can be any type - not just strings - and insertion order is always preserved. `Set` stores a collection where every value is guaranteed unique; adding a duplicate is silently ignored. Both are iterable and track their own `.size`.
Codeeditable — Run and Step both follow your edits
Loading...
Console
Output will appear here
Visualization
Result
Press Step to watch each line's result appear here
Why?
The second seen.add("a") is a duplicate - Set silently ignores it, so size stays at 2 instead of climbing to 3.