arrow function in object javascript code example
Example 1: javascript return object in arrow function
const func = () => ({ foo: "bar" });
console.log(func());
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: Arrow Functions
const magic = function() {
return new Date();
};
const magic = () => {
return new Date();
};
const magic = () => new Date();
Example 4: how to make javascript function consise
multiplyfunc = (a, b) => { return a * b; }
Example 5: how to make arrow functions as object methods
var chopper = {
owner: 'Zed',
getOwner: function() {
return this.owner;
}
};
var chopper = {
owner: 'Zed',
getOwner() {
return this.owner;
}
};