0 votes
in JavaScript by
Explain about the JavaScript weakMap set() Method?

1 Answer

0 votes
by

The weakMap.set() is an inbuilt function in JavaScript which is used to set a new element with a particular key and value to a WeakMap object. 

Syntax:

weakMap.set(key, value);

Parameters: It takes parameters “key” which is the key of the element which is to set to the WeakMap object and parameter “value” is the value of the element to set to the WeakMap object. 

Return value: It returns the WeakMap object. 

function gfg() { 
    const weakmap1 = new WeakMap();
  
    const key1 = {};
    const key2 = {};
    const key3 = {};
  
    weakmap1.set(key1, 'G');
    weakmap1.set(key2, 'F');
    weakmap1.set(key3, 'G');
  
    document.write(weakmap1.get(key1) 
    +weakmap1.get(key2)
    +weakmap1.get(key3));
}
...