types of arrow functions code example
Example 1: typescript arrow function
let sum = (x: number, y: number): number => {
return x + y;
}
sum(10, 20);
Example 2: js arrow function
const add = (a, b) => a + b;
const square = num => {
return num * num;
}
const rollDie = () => (
Math.floor(Math.random() * 6) + 1
)
Example 3: pass a variable by reference to arrow function
params => ({foo: bar})
(param1, param2, ...rest) => { statements }
(param1 = defaultValue1, param2, …, paramN = defaultValueN) => {
statements }
var f = ([a, b] = [1, 2], {x: c} = {x: a + b}) => a + b + c;
f();