WeakMap.prototype.has() — JS Technical Interview Questions & Answers
Checks whether an object key exists.
WeakMap.prototype.has()
- WeakMap.prototype.has() is a JS topic. In plain words you use it for fail students only in a marks list. Don’t start with a slogan — start with that picture.
- Smallest example: filter(m => m < 40). Type it, run it, and say what you see. If you can do that from memory, you know WeakMap.prototype.has().
- From the example next to this theory: Checks whether an object key exists.
- Trap: mutating while filtering. Fix that before you talk about advanced JS.
- Viva: what is WeakMap.prototype.has()? Then show filter(m => m < 40). Then name the trap.
Technical Interview Tip: What is WeakMap.prototype.has()? Show this: filter(m => m < 40). Trap: mutating while filtering.
Code Examples for WeakMap.prototype.has()
WeakMap.prototype.has() — working example
const secret = new WeakMap();
const user = { id: 1 };
secret.set(user, "token-abc");
console.log(secret.get(user));
console.log(secret.has(user));WeakMap.prototype.has() — weakMap keys must be objects; entries do not prevent GC of those keys.
How to Explain WeakMap.prototype.has() to an Interviewer
What is WeakMap.prototype.has()?
Used for fail students only a marks list Not just the heading
Give one small example of WeakMap.prototype.has().
filter(m => m < 40) Checks whether an object key exists
What mistake do beginners make with WeakMap.prototype.has()?
mutating while filtering Show the fix
Where do you use WeakMap.prototype.has()?
a marks list fail students only