TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #3029 3.06K
CHALLENGE


class Session {
#id;
constructor(id) {
this.#id = id;
}
getId() { return this.#id; }
}

const activeSessions = new WeakSet();

const s1 = new Session("user_42");
const s2 = new Session("user_99");
let s3 = new Session("user_07");

activeSessions.add(s1);
activeSessions.add(s2);
activeSessions.add(s3);

console.log(activeSessions.has(s1)); // line A
console.log(activeSessions.has(s3)); // line B

s3 = null;

console.log(activeSessions.has(s3)); // line C

activeSessions.delete(s2);
console.log(activeSessions.has(s2)); // line D
console.log(activeSessions.size); // line E
  • ❤ 7
  • 👍 3
  • 🔥 1
More from @javascript
  1. Sep 25, 2026Post #3518
  2. Sep 25, 2026CHALLENGE let counter = 0; const mod = { get counter() { return counter; }, increment() {…
  3. Sep 24, 2026Post #3516
  4. Sep 24, 2026CHALLENGE class Base { static count = 0; static increment() { this.count++; return this.co…
  5. Sep 23, 2026🤩 tinyjs: Build JavaScript Desktop Apps in <10MB I built an app with this and was impress…
  6. Sep 23, 2026Post #3513
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 →