arrow function return javascript code example
Example 1: javascript return object in arrow function
const func = () => ({ foo: "bar" });
console.log(func());
Example 2: js anonymous function es6
var multiplyES5 = function(x, y) {
return x * y;
};
const multiplyES6 = (x, y) => { return x * y };
Example 3: js arrow function
const add = (a, b) => a + b;
const square = num => {
return num * num;
}
const rollDie = () => (
Math.floor(Math.random() * 6) + 1
)
Example 4: arrow function javascript
let myFunction = (arg1, arg2, ...argN) => expression
let myFunction = (arg1, arg2, ...argN) => {
statement(s)
}
let hello = (arg1,arg2) => "Hello " + arg1 + " Welcome To "+ arg2;
console.log(hello("User","Grepper"))