Aryan PrajapatKnowledge Contributor
What are the differences between WeakSet and Set
What are the differences between WeakSet and Set
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it. Other differences are,
Sets can store any value Whereas WeakSets can store only collections of objects
WeakSet does not have size property unlike Set
WeakSet does not have methods such as clear, keys, values, entries, forEach.
WeakSet is not iterable.