Explore Library
Code Quiz

Set vs Object Membership Check

Spot the bug in a duplicate-detection function that misuses a Set as if it were a plain object.

Codejavascript
function hasDuplicates(arr) {
  const seen = new Set();
  for (const value of arr) {
    if (seen[value]) {
      return true;
    }
    seen.add(value);
  }
  return false;
}

console.log(hasDuplicates([1, 2, 3, 2])); // expected: true

This function should return true when the array contains duplicates, but it always returns false. What is the bug?