What symbol is used to declare private fields in JavaScript classes?

The story behind the answer

In JavaScript classes, the # symbol declares a private field that can be accessed only from within the class that defines it.

For example, `class Wallet { #balance = 0; }` creates a field that outside code cannot read with `wallet.#balance`; that access causes a syntax error. A class method can use `this.#balance`, allowing the class to control how its internal state is viewed or changed.

JavaScript's # private fields are genuine language-level private elements, not merely naming conventions. They are distinct from properties written with an underscore, which remains publicly accessible, and from older closure-based techniques that hid state through function scope. The feature was standardized with other class-element improvements in ECMAScript 2022.

The # is part of the field's name, so `#balance` and `balance` are different members. Private fields are also separate from string-keyed properties: bracket notation such as `object["#balance"]` does not access them. A related `#field in object` syntax can test whether an object carries a particular private brand.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: