TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2952 3.34K
CHALLENGE

const wm = new WeakMap();
let obj1 = { name: 'John' };
let obj2 = { name: 'Jane' };

wm.set(obj1, 'developer');
wm.set(obj2, 'designer');

console.log(wm.get(obj1));
console.log(wm.has(obj2));

obj1 = null;
console.log(wm.get(obj1));

const normalObj = {};
try {
wm.set('string', 'value');
} catch (e) {
console.log('error');
}
  • 👍 6
  • 🔥 2
More from @javascript
  1. Sep 27, 2026Post #3522
  2. Sep 27, 2026CHALLENGE class Base { value = 10; getValue = () => this.value; constructor() { this.value…
  3. Sep 26, 2026Post #3520
  4. Sep 26, 2026CHALLENGE const obj = { value: 42, getValue() { return this?.value; }, getValueArrow: () =…
  5. Sep 25, 2026Post #3518
  6. Sep 25, 2026CHALLENGE let counter = 0; const mod = { get counter() { return counter; }, increment() {…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →