JS Built-ins
← Set68 / 85
SetsymmetricDifferenceintermediate

Set symmetricDifference() β€” identical sets β†’ empty

πŸ“– Usage Example
const a = new Set([1, 2, 3])
const b = new Set([2, 3, 4])
const sym = a.symmetricDifference(b)
console.log([...sym]) // β†’ [1, 4]

Use Set.symmetricDifference() to get elements in either set but not in both.

Set.prototype.symmetricDifference() (ES2025)

Identical Sets have an empty symmetric difference.

Challenge: Verify that symmetric difference of identical Sets is empty.

πŸ’‘ Hints (1)
  • β€’ When A equals B, symmetric difference is empty β€” all elements are in both