Arrow functions in typescript are another way of writing fucntion.Arrow function allows us to write functions in a compact manner.

We write a normal function as:

1 2 3 | function square(a:number): number { return a*a; } |

the above function returns the square of passed argument.

We can write arrow function for the above function as:

1 | var square =(a) =>a*a; |

as you can see above in the case of arrow function we have replaced the body of the function.When we write arrow function we don’t write the function body as in the case of normal function.Instead we write input argument followed by the arrow operator and then the expression.

So the syntax to write arrow function is :

1.write arguments enclosed in parenthesis ,e.g (a,b)

2.write arrow operator =>

3. write the expression

Assign the expression to a variable and call the expression using this variable.

## Leave a Reply