Map and Set in JavaScript

What number is produced?

Examples

Worked example

Input
new Set(['red', 'red', 'blue']).size
Expected output
2

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The string red appears twice but is stored once. Blue adds one more distinct entry.

Back to the lesson