Different types of function declaration (foo () : void{} vs foo() {}) Angular2

So I was doing some tutorials on angular 2 when I found on their (angular.io) tutorial page this function declaration:

foo () : void {}

My question is… What’s the difference between that declaration and this?

foo() {}

I’ve figured out that the void is the return type but if you put for instance string instead of void both functions are able to return strings.

So whats the real difference and what is the best practice? ( I’m inclined to say the first one, just don’t know why).

And is that a Javascript, TypeScript, ES6 or even an Angular2 thing? Never seen that before.

Leave a Comment