javascript arrow functions this code example
Example 1: javascript arrow function
let add = function(x,y) {
return x + y;
}
console.log(add(10,20));
let add = (x,y) => x + y;
console.log(add(10,20));
let add = (x, y) => { return x + y; };
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: concise body arrow functions javascript
const plantNeedsWater = day => day === 'Wednesday' ? true : false;
Example 4: es6 arrow function
const prices = smartPhones.map(smartPhone => smartPhone.price);
console.log(prices);