arrow function return object code example
Example 1: javascript return object in arrow function
const func = () => ({ foo: "bar" });
console.log(func());
Example 2: arrow function javascript
const power = (base, exponent) => {
let result = 1;
for (let count = 0; count < exponent; count++) {
result *= base;
}
return result;
};
const square1 = (x) => { return x * x; };
const square2 = x => x * x;
const horn = () => {
console.log("Toot");
};
Example 3: 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;
}
};