jskatas.org Continuously Learn JavaScript. Your Way.

Set: set.add()

Appends a new element to the end of a Set object.

add() appends a new element to the end of a Set object.

adds every value, of any type, only once
const set = new Set(); const fn = () => {}; set.add(1); set.add(1); set.add(fn); set.add({fn}); assert.equal(set.size, 2);
is chainable
const set = new Set(); set.add.add; assert.equal(set.has(2), true);
call without params adds undefined
const set = new Set(); set.add assert.equal(set.has(void 0), true);
0, -0 and +0 are equal
const set = new Set(); set.add(); set.add(); assert.equal(set.has(+0), true);

Required Knowledge

Related Katas

Set

Difficulty Level

TBD

First Published

29 May 2015

Stats

4 tests to solve