WeakSet.prototype.add() — JS Technical Interview Questions & Answers
Adds an object to the WeakSet.
WeakSet.prototype.add()
- WeakSet.prototype.add() is a JS topic. In plain words you use it for class Student in a tiny OOP file. Don’t start with a slogan — start with that picture.
- Smallest example: class Student { constructor(name) {} }. Type it, run it, and say what you see. If you can do that from memory, you know WeakSet.prototype.add().
- From the example next to this theory: Adds an object to the WeakSet.
- Trap: arrow function for a method that needs this. Fix that before you talk about advanced JS.
- Viva: what is WeakSet.prototype.add()? Then show class Student { constructor(name) {} }. Then name the trap.
Technical Interview Tip: What is WeakSet.prototype.add()? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.
Code Examples for WeakSet.prototype.add()
WeakSet.prototype.add() — working example
const seen = new WeakSet();
const node = { tag: "button" };
seen.add(node);
console.log(seen.has(node));WeakSet.prototype.add() — weakSet stores object uniqueness without preventing garbage collection.
How to Explain WeakSet.prototype.add() to an Interviewer
What is WeakSet.prototype.add()?
Used for class Student a tiny OOP file Not just the heading
Give one small example of WeakSet.prototype.add().
class Student { constructor(name) {} } Adds an object to the WeakSet
What mistake do beginners make with WeakSet.prototype.add()?
arrow function for a method that needs this Show the fix
Where do you use WeakSet.prototype.add()?
a tiny OOP file class Student