WeakMap and WeakSet Flashcards

1
Q

The first difference between Map and WeakMap is that keys must be ________

A

objects, not primitive values:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

let weakMap = new WeakMap();
let obj = {};
weakMap.set(obj, “ok”); // returns?

A

works fine (object key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

let weakMap = new WeakMap();

let obj = {};

weakMap.set(“test”, “Whoops”); //

A

Error, because “test” is not an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

WeakMap has only the following methods (4);

A

weakMap.set(key, value)
weakMap.get(key)
weakMap.delete(key)
weakMap.has(key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

WeakMap does not support iteration and methods (3)

A

keys(), values(), entries()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

______ is Set-like collection that stores only objects and removes them once they become inaccessible by other mean

A

WeakSet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly