TGViewer
JavaScript JavaScript @javascript · 31K subscribers
Post #3567 144
CHALLENGE

class Counter {
#count = 0;
get value() {
return this.#count;
}
set value(v) {
if (v < this.#count) throw new RangeError('Cannot decrease');
this.#count = v;
}
}

const c = new Counter();
c.value = 5;
let msg;
try {
c.value = 3;
} catch (e) {
msg = e.message;
}
c.value = 10;
console.log(msg, c.value);
More from @javascript
  1. Oct 18, 2026Post #3568
  2. Oct 17, 2026Post #3566
  3. Oct 17, 2026CHALLENGE async function run() { const results = await Promise.allSettled([ Promise.resolv…
  4. Oct 16, 2026Post #3564
  5. Oct 16, 2026CHALLENGE const x = 0; const y = ''; const z = null; const r1 = x ?? y ? 'A' : 'B'; const…
  6. Oct 15, 2026🤟 You Don’t Know Node.js EventLoop (30 min read) You might be wondering if the title of t…
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 →