🟑 MediumClosures & ScopeπŸ’» Output Question

Set uniqueness rules

πŸ’‘

Hint

Set uses SameValueZero for uniqueness: 1 !== "1", NaN === NaN (special case), undefined and null are distinct values.

What does this output?

const set = new Set([1, '1', true, 1, NaN, NaN, null, undefined, null]);

console.log(set.size);
console.log([...set]);

Correct Output

6
[1, '1', true, NaN, null, undefined]

Why this output?

Explanation: 1 (number) and "1" (string) are different values. 1 appears twice β€” deduplicated. NaN appears twice β€” Set treats NaN === NaN (unlike === operator), so deduplicated. null twice β€” deduplicated. Result: 1, "1", true, NaN, null, undefined = 6 items.

Key Insight: Set uses SameValueZero for uniqueness: 1 !== "1", NaN === NaN (special case), undefined and null are distinct values.

More Closures & Scope Output Questions

🟒 EasyClassic var in loop closureβ†’πŸŸ’ Easylet in loop closure (fix)β†’πŸŸ‘ MediumClosure counterβ†’πŸŸ‘ MediumIIFE closureβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz