Interview GURU

What is the use of a WeakSet object in JavaScript?

The JavaScript WeakSet object is the type of collection that allows us to store weakly held objects. Unlike Set, the WeakSet are the collections of objects only. It doesn't contain the arbitrary values. For example:

function display()  
{  
var ws = new WeakSet();    
var obj1={};    
var obj2={};    
ws.add(obj1);    
ws.add(obj2);    
//Let's check whether the WeakSet object contains the added object    
document.writeln(ws.has(obj1)+"<br>");    
document.writeln(ws.has(obj2));     
}     
display()