JS Built-ins
← Set11 / 85
Setaddbeginner

Set add() β€” returns same Set

πŸ“– Usage Example
const s = new Set()
s.add(1)
s.add(2)
s.add(1)   // duplicate ignored
console.log(s.size) // β†’ 2

Use Set.add() to insert values; duplicates are silently ignored.

Set.prototype.add()

add() adds a value and returns the Set itself for chaining.

Challenge: Verify that add() returns the same Set instance.

πŸ’‘ Hints (1)
  • β€’ add() returns the Set itself, enabling method chaining