Open this example in the interactive library
Source code
class Counter {
#count = 0;
increment() {
return ++this.#count;
}
}
const count = new Counter();
console.log(count.increment(), count.increment());
Sample output
1 2

Open this example in the interactive library
class Counter {
#count = 0;
increment() {
return ++this.#count;
}
}
const count = new Counter();
console.log(count.increment(), count.increment());
1 2