-1

What is the difference, if any, between:

@Output() exampleChange: EventEmitter<Example> = new EventEmitter();

and

@Output() exampleChange = new EventEmitter<Example>();

ebakunin
  • 3,621
  • 7
  • 30
  • 49

2 Answers2

3

No difference, is practically the same.

This defines the type and then initializes it:

@Output() exampleChange: EventEmitter<Example> = new EventEmitter();

This is initialized directly:

@Output() exampleChange = new EventEmitter<Example>();

I recommend using the second way

0

think about it when you set a variable in a component

export class MyTestComponent {
  myNumber:number = 10;
}
-------------------------------------
export class MyTestComponent {
  myNumber = 10;
}

In both examples, I created a variable that calls myNumber and set his value to 10, but in the second one, I gave it a type. in JS there is no difference between the code except the good order of the script

Matan Shushan
  • 1,204
  • 1
  • 10
  • 25