WeakMap.prototype.delete() — JS Technical Interview Questions & Answers
Removes an entry by object key.
WeakMap.prototype.delete()
- WeakMap.prototype.delete() is a JS topic. In plain words you use it for let total = 0 in a cart script. Don’t start with a slogan — start with that picture.
- Smallest example: let for change, const for fixed. Type it, run it, and say what you see. If you can do that from memory, you know WeakMap.prototype.delete().
- From the example next to this theory: Removes an entry by object key.
- Trap: var leak / const reassign. Fix that before you talk about advanced JS.
- Viva: what is WeakMap.prototype.delete()? Then show let for change, const for fixed. Then name the trap.
Technical Interview Tip: What is WeakMap.prototype.delete()? Show this: let for change, const for fixed. Trap: var leak / const reassign.
Code Examples for WeakMap.prototype.delete()
WeakMap.prototype.delete() — 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.delete() — weakMap keys must be objects; entries do not prevent GC of those keys.
How to Explain WeakMap.prototype.delete() to an Interviewer
What is WeakMap.prototype.delete()?
Used for let total = 0 a cart script Not just the heading
Give one small example of WeakMap.prototype.delete().
let for change, const for fixed Removes an entry by object key
What mistake do beginners make with WeakMap.prototype.delete()?
var leak / const reassign Show the fix
Where do you use WeakMap.prototype.delete()?
a cart script let total = 0