javascript arrow function return code example
Example 1: javascript return object in arrow function
const func = () => ({ foo: "bar" });
console.log(func()); // { foo: "bar" }
Example 2: js arrow function
// const add = function(x,y) {
// return x + y;
// }
// const add = (x, y) => {
// return x + y;
// }
const add = (a, b) => a + b;
const square = num => {
return num * num;
}
// const rollDie = () => {
// return Math.floor(Math.random() * 6) + 1
// }
const rollDie = () => (
Math.floor(Math.random() * 6) + 1
)
Example 3: how to make javascript function consise
multiplyfunc = (a, b) => { return a * b; }