Map and WeakMap

Map

key-value pairs and with insertion order of the keys, key and value can be objects or primitive values map has iterability

WeakMap

collection of key/value pair, and the keys must be object(Symbol and primitive are not allowed), values can be any javascript type weakmap has no iterability entrie are garbage collected dependented, which means if the object has been cleared by garbage collected, it would removed from weakmap automatically

instnace methods

let a = new WeakMap()
{
    let b = {b: 1}
    b.set(b, 1)
    console.log(a) // a = WeakMap({...} => 1)
}
console.log(a) // a = WeakMap{}