Expressions and patterns

Private class field

Try the free JavaScript compiler

Declares private instance state accessible only through permitted class-private syntax. Private elements are not ordinary string or symbol properties.

Formal Syntax & Structure

javascript syntaxjavascript
class C { #field = value; read() { return this.#field; } }

Working Example

Example Snippetjavascript
class C{#n=3;read(){return this.#n;}}console.log(new C().read());
JavaScript Reference