set

Estimated reading time: 1 minute

set

  • store reference
  • grabage
let set = new Set(),
    key = {null};
set.add(key);
console.log(set.size);
// 1

waekset

  • don’t store reference
  • no garbage
let set = new WeakSet(),
    key = {null};
set.add(key);
console.log(set.size);
// undefined