Advertisement
728x90
A WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. In this case, keys must be objects and the values can be arbitrary values. The syntax looks like the following:
javascript
1new WeakMap([iterable]);Let's see the below example to explain it's behavior,
javascript
1var ws = new WeakMap();
2
3var user = {};
4
5ws.set(user);
6
7ws.has(user); // true
8
9ws.delete(user); // removes user from the map
10
11ws.has(user); // false, user has been removedAdvertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 37
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
207of476