Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 744 Bytes

what_is_a_weakset.md

File metadata and controls

18 lines (12 loc) · 744 Bytes

What is a WeakSet?

A WeakSet is a collection of objects where each object is held weakly. This means the objects in a WeakSet are not prevented from being garbage-collected when there are no other references to them. It only accepts objects, and it does not allow duplicates.

Example:

const obj1 = { name: 'John' };
const obj2 = { name: 'Jane' };
const weakset = new WeakSet([obj1, obj2]);
console.log(weakset.has(obj1)); // true

Tags: basic, JavaScript, collections

URL: https://www.tiktok.com/@jsmentoring/photo/7461719258490211617