0

I referred to this documentation on the ionic site, to integrate firebase with my mobile application.

this.firebase.getToken()
  .then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
  .catch(error => console.error('Error getting token', error));

this.firebase.onTokenRefresh()
  .subscribe((token: string) => console.log(`Got a new token ${token}`));

As seen in the above code, the 'then', 'catch' and 'subscribe' methods seem to have a variable followed by the "=>" symbol. Does this symbol have a generic meaning or does it vary from method to method? What exactly does it mean?

EDIT: Since this question is marked duplicate by others, I thought it was a new feature in typescript that I was not aware of. In JavaScript, I had always used the old school method as pointed in one of the answers. It might help others like me, however.

thegreatcoder
  • 2,173
  • 3
  • 19
  • 28

1 Answers1

1

It's a lambda expression, which is basically a function that is passed as an argument to methods such as then and subscribe, and is called by those methods once they receive an emission.

token => console.log(`The token is ${token}`)

It's a function that takes a token as argument, and logs it.

The argument is passed by the then function, when it invokes your lambda expression. If that makes sense?

Wingnod
  • 595
  • 3
  • 9