FrontendDeveloper.in

JavaScript question detail

What is a WeakMap

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:

new WeakMap([iterable]);

Let's see the below example to explain it's behavior,

var ws = new WeakMap();
var user = {};
ws.set(user);
ws.has(user); // true
ws.delete(user); // removes user from the map
ws.has(user); // false, user has been removed
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399