The WeakMap object is basically a collection of key or value pairs where the keys are weakly referenced. It provides a way for extending objects from the outside without meddling into the garbage collection.

Here are some use cases of Weakmap objects:
  • Maintaining private data about a specific object while only giving access to people having a reference to the Map.
  • Safekeeping of data related to the library objects without making any changes to them or incurring any overhead.
  • Keeping of data related to the host objects such as DOM nodes in the browser.
BY Best Interview Question ON 20 Jun 2020