What is the Underscore for in front of the arrow function (_=>) in the hero.service.ts Angular v5 Tour of Heroes Tutorial?

() => {console.log('Hello World')}

  _ => {console.log('Hello World')}

Both of the above are just the same if your function doesn't need a parameter.

The underscore _ is just a throwaway variable, meaning it can be any variable name since it will never be used. It's just that they usually use the underscore to say that the function doesn't need a parameter.

I write my functions with no parameters using ()=>, but I've seen a lot of versions using the underscore so it's good to understand both.


Its nothing but a notion to name a parameter which isn't going to be used in the function.

Instead, they would have written it like this:

tap(() => this.log(`updated hero id=${hero.id}`)),

If you want to read more, this post is a good start.