InterviewHubPRO
Section Overview
Q210

Question 210 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

40%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

List down the collection of methods available on WeakSet

Below are the list of methods available on WeakSet,

  1. add(value): A new object is appended with the given value
  2. delete(value): Deletes the value from the collection.
  3. has(value): It returns true if the value is present in the collection, otherwise it returns false.

Let's see the functionality of all the above methods in an example,

javascript
  var weakSetObject = new WeakSet();
  var firstObject = {};
  var secondObject = {};
  // add(value)
  weakSetObject.add(firstObject);
  weakSetObject.add(secondObject);
  console.log(weakSetObject.has(firstObject)); //true
  weakSetObject.delete(secondObject);