Analyzing set and map types

Before actually using sets and maps, we will need to understand when and where we need to use them. Each data structure whether native or custom has its own strengths and weaknesses. 

Not only is it important to utilize these strengths, it's much more important to avoid their weaknesses. To understand some of these, we will explore set and map types and why they are needed and where to employ them. 

There are primarily four different set and map types:

  • Map: A key-value pair in which the key can either be an Object or a primitive and can hold any arbitrary value.
  • WeakMap: A key-value pair in which the key can only be an Object and can hold any arbitrary value. The Keys are weakly referenced; this means that they are not prevented from being garbage-collected if not in use.
  • Set: Data type that allows a user to store unique values of any type.
  • WeakSet: Similar to set, but maintains a weak reference.