Lambda Function/Arrow Function -
The arrow function is additional feature in typescript and it is also known as a lambda function.
A lambda function is a function without a name.
var addNum = (n1: number, n2: number) => n1 + n2;
In the above, the “=>” is a lambda operator and (n1 + n2) is the body of the function and (n1: number, n2: number) are inline parameters.
For example –
let addNum = (n1: number, n2: number): number => { return n1 + n2; } let multiNum = (n1: number, n2: number): number => { return n1 * n2; } let dividNum = (n1: number, n2: number): number => { return n1 / n2; } addNum(10, 2);// Result - 12 multiNum(10, 2);// Result - 20 multiNum(10, 2);// Result - 5
I hope you are enjoying with this post! Please share with you friends.
Thank you!!