What is the effect of adding '$' dollar sign infront of event in Angular?
onModelUpdated($event: any) {
console.log($event);
}
vs
onModelUpdated(event: any) {
console.log(event);
}
$
prefix in variable names has no any kind of an effect. A $
dollar sign in JavaScript (and TypeScript by extension) is a valid identifier to use as part of a variable name, it carries no syntactical meaning. It can be used in the beginning, middle or end of a variable/function name.
Specifically when it comes to $event
and its use in Angular, it is more of a convention carried over from the days of AngularJS. In AngularJS, internal variables exposed by the framework were prefixed with a $
.
That is why sometimes you see event
and other times $event
.
There was a proposal to get rid of it, but nothing happened.
So it is more of a question of style and conventions, and it is up to the personal/project preferences to come up with a convention about whether to use $event
or event
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With