WeakSet.prototype.has() — JS Technical Interview Questions & Answers

Checks whether an object exists in the WeakSet.

WeakSet.prototype.has()

  • WeakSet.prototype.has() 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.has().
  • From the example next to this theory: Checks whether an object exists in the WeakSet.
  • Trap: arrow function for a method that needs this. Fix that before you talk about advanced JS.
  • Viva: what is WeakSet.prototype.has()? Then show class Student { constructor(name) {} }. Then name the trap.

Technical Interview Tip: What is WeakSet.prototype.has()? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.

Code Examples for WeakSet.prototype.has()

WeakSet.prototype.has() — working example

const seen = new WeakSet();
const node = { tag: "button" };
seen.add(node);
console.log(seen.has(node));

WeakSet.prototype.has() — weakSet stores object uniqueness without preventing garbage collection.

How to Explain WeakSet.prototype.has() to an Interviewer

What is WeakSet.prototype.has()?

Used for class Student a tiny OOP file Not just the heading

Give one small example of WeakSet.prototype.has().

class Student { constructor(name) {} } Checks whether an object exists in the WeakSet

What mistake do beginners make with WeakSet.prototype.has()?

arrow function for a method that needs this Show the fix

Where do you use WeakSet.prototype.has()?

a tiny OOP file class Student