how to define arrow function in javascript code example
Example 1: javascript arrow function
let add = function(x,y) {
return x + y;
}
console.log(add(10,20));
let add = (x,y) => x + y;
console.log(add(10,20));
let add = (x, y) => { return x + y; };
Example 2: arrow func in javascript
const greet = (who) => {
return `Hello, ${who}!`;
};
greet('Eric Cartman');
Example 3: how to make javascript function consise
multiplyfunc = (a, b) => { return a * b; }
Example 4: arrow function javascript
function (a, b){
let chuck = 42;
return a + b + chuck;
}
(a, b) => {
let chuck = 42;
return a + b + chuck;
}