WeakMap and WeakSet Flashcards
1
Q
The first difference between Map and WeakMap is that keys must be ________
A
objects, not primitive values:
2
Q
let weakMap = new WeakMap();
let obj = {};
weakMap.set(obj, “ok”); // returns?
A
works fine (object key)
3
Q
let weakMap = new WeakMap();
let obj = {};
weakMap.set(“test”, “Whoops”); //
A
Error, because “test” is not an object
4
Q
WeakMap has only the following methods (4);
A
weakMap.set(key, value)
weakMap.get(key)
weakMap.delete(key)
weakMap.has(key)
5
Q
WeakMap does not support iteration and methods (3)
A
keys(), values(), entries()
6
Q
______ is Set-like collection that stores only objects and removes them once they become inaccessible by other mean
A
WeakSet