Private Class Fields and Methods
JavaScript's class field syntax, now widely supported, includes true private fields using the # prefix. Private fields can only be accessed inside the class body — not from subclasses, not from external code — providing genuine encapsulation rather than just convention-based privacy.
Private Fields
Declare a private field at the top of the class body with #fieldName;. Access and modify it anywhere inside the class with this.#fieldName. Any attempt to access it from outside throws a SyntaxError.
Private Methods
Prefix a method with # to make it private. Private methods can only be called from within the class. They are ideal for internal helper logic that should not be part of the public API.
in Operator for Private Fields
Use #field in obj to check if an object has a specific private field — useful for type-checking inside static methods.