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.

34 thoughts on “Different types of function declaration (foo () : void{} vs foo() {}) Angular2”

  1. 89277 188454Thanks for the post. I like your writing style – Im trying to start a weblog myself, I believe I might read thru all your posts for some suggestions! Thanks once much more. 207358