/*
SIMPLE EXPLANATION:
The WeakMap takes only objects as keys.
When one object is not being referred to anymore, it and its
associated value will get removed from the WeakMap.
The WeakSet functions similarly.
Its values are unique and are only objects.
When one object is not being referred to anymore, it will get removed
from the WeakSet.
*/
const weakMap = new WeakMap();
console.log(weakMap); // WeakMap {}
let obj = {};
// adding object (element) to WeakMap
weakMap.set(obj, 'hello');
console.log(weakMap); // WeakMap {{} => "hello"}
const weakMap = new WeakMap();
console.log(weakMap); // WeakMap {}
let obj = {};
// adding object (element) to WeakMap
weakMap.set(obj, 'hello');
console.log(weakMap); // WeakMap {{} => "hello"}
// get the element of a WeakMap
console.log(weakMap.get(obj)); // hello
// check if an element is present in WeakMap
console.log(weakMap.has(obj)); // true
// delete the element of WeakMap
console.log(weakMap.delete(obj)); // true
console.log(weakMap); // WeakMap {}
const weakMap = new WeakMap();
console.log(weakMap); // WeakMap {}
let obj = {};
// adding object (element) to WeakMap
weakMap.set(obj, 'hello');
console.log(weakMap); // WeakMap {{} => "hello"}
// get the element of a WeakMap
console.log(weakMap.get(obj)); // hello
// check if an element is present in WeakMap
console.log(weakMap.has(obj)); // true
// delete the element of WeakMap
console.log(weakMap.delete(obj)); // true
console.log(weakMap); // WeakMap {}