EasyModern JS💻 Output Question

Set deduplicates and preserves insertion order

💡

Hint

Set stores unique values in insertion order. Adding a duplicate is silently ignored.

What does this output?

const set = new Set([1, 2, 3, 2, 1, 3, 4]);
console.log(set.size);
set.add(5); set.add(1);
console.log(set.size);
console.log([...set][0]);

Correct Output

4
5
1

Why this output?

Explanation: Duplicates removed: {1,2,3,4}=size 4. add(5)→5. add(1) already exists, no change. First element=1.

Key Insight: Set stores unique values in insertion order. Adding a duplicate is silently ignored.

More Modern JS Output Questions

EasyDestructuring defaults apply only for undefinedEasyObject spread — later properties winMediumOptional chaining prevents TypeError on missing propertiesMediumNullish coalescing ?? vs OR ||

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz