arrow function inside object code example

Example 1: javascript return object in arrow function

const func = () => ({ foo: "bar" });
console.log(func()); // { foo: "bar" }

Example 2: es6 arrow function

const multiplyES6 = (x, y) => x * y;

Example 3: Arrow Functions

// The usual way of writing function
const magic = function() {
  return new Date();
};

// Arrow function syntax is used to rewrite the function
const magic = () => {
  return new Date();
};
//or
const magic = () => new Date();

Example 4: how to make arrow functions as object methods

var chopper = {
    owner: 'Zed',
    getOwner: function() {
        return this.owner;
    }
};

// or

var chopper = {
    owner: 'Zed',
    getOwner() {
        return this.owner;
    }
};