Checking if a value exists

suggest change

To check whether a value is in a WeakSet, use .has(). Only objects can be members. .has() returns false for a primitive; it does not throw.

const obj1 = {},
      obj2 = {};

const weakset = new WeakSet([obj1]);
console.log(weakset.has(obj1)); // true
console.log(weakset.has(obj2)); // false

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents