0

I came across the scenario in Angular 11 where the variable is declared with $ symbol.

e.g. $testVar = new Subject<Type[]>(this.name);

What is the meaning of this declaration with $ symbol?

4
  • 2
    The dollar symbol is more often used as a suffix, not a prefix. Maybe this answer will help : stackoverflow.com/a/37928549/6444705 Commented Aug 19, 2021 at 14:01
  • 1
    Does this answer your question? angular2 style guide - property with dollar sign? Commented Aug 19, 2021 at 14:15
  • @AustinTFrench - I understand when $ added as a suffix to indicate an observable but in one case I observed it as prefix. So just curious to know if it has any significance. Thanks Commented Aug 20, 2021 at 6:42
  • $ prefix meant a DOM node in jQuery. BTW, # prefix marks a variable as a JavaScript Private Field. Commented Dec 14, 2022 at 20:39

1 Answer 1

2

It does not have any special function in TypeScript but there is a convention of using $ symbol in the name of the variable which stores an Observable. As Subject would create an Observable it might be used for this purpose here.

However the more common version of this is to use $ as suffix like this testVar$ - seeing that I would expect an Observable to be stored there.

But I would not use this suffix for variable storing the subject but rather the final Observable.


testSubject = new Subject<Type[]>(this.name);
test$ = testSubject.asObservable();

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Luksz for the clarification. I used $ as a suffix for the observable but was curious if it has any significance if it used as a prefix. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.