skip to Main Content

What does # mean as a prefix for Typescript or Javascript class attribute name?

export class MyFacade {
  #state: MyState = {
    isLoading: true
  };

  readonly #store = new BehaviorSubject<MyState>(this.#state);
}

2

Answers


  1. Chosen as BEST ANSWER

    The sharp sign # means the attribute is private and is only accessible from within the class.

    Typescript private is only checked at compilation when it transpiles to Javascript but the attribute can still be accessed and modified at runtime.

    myFacade['typescriptPrivateAttribute'] = 'newValue';

    Source


  2. in typescript or javascript if you use # before class attribute name like #state or #store, it means attribute is private to the class, so the attribute will be only accessed or modified within the class itself

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search