DEV Community

Discussion on: JavaScript Quiz Question #2: A Set of Objects

Collapse
 
kenbellows profile image
Ken Bellows

A, because separate objects are not deduped by a Set, even if they happen to have an identical structure and values. If you wanted it to log B, you'd have to do this:

const o = {a: 1}
const mySet = new Set([o, o])
const result = [...mySet]
console.log(result)

Here the object does get deduped because it's the same exact object instance twice, not two different object instances that looks the same.