Interview GURU

What is the use of a WeakMap object in JavaScript?

The JavaScript WeakMap object is a type of collection which is almost similar to Map. It stores each element as a key-value pair where keys are weakly referenced. Here, the keys are objects and the values are arbitrary values. For example:

function display()  
var wm = new WeakMap();    
var obj1 = {};    
var obj2 = {};    
var obj3= {};    
wm.set(obj1, "jQuery");    
wm.set(obj2, "AngularJS");