JavaScript › Classes & Class Syntax
What are class fields, and how do they differ from constructor-assigned properties?
IntermediateAnswer
Class fields let you declare and initialize instance properties directly in the class body, outside the constructor, which runs before the constructor body executes. They reduce boilerplate especially with inheritance and default values.
class Counter {
count = 0; // class field
increment() { this.count++; }
}Real-world example Declaring default component state fields cleanly at the top of a class, without cluttering the constructor.