Class fields, private # fields, static members
Create classes with public fields, hide data with private # fields, and add static properties/methods.
Why classes?
Goal: Build small, clear classes.
- Public fields and methods
- #private fields for hidden state
- static properties/methods for class-level helpers
- Keep examples tiny and readable

Public fields & constructor
Create a class with a public field and small methods; keep logic simple for beginners.
// Public fields and a simple method
class Counter {
// public field with default
value = 0;
constructor(start) {
// use a default if start is not provided
this.value = Number.isFinite(start) ? start : 0;
}
inc() {
this.value = this.value + 1;
}
}
const c1 = new Counter(2);
c1.inc();
console.log("value:", c1.value); // 3

All lessons in this course
- Class fields, private # fields, static members
- Inheritance, super, and when to prefer composition
- Mixins (taste) — simple reuse without deep hierarchies