use of arrow function javascript 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: arrow function javascript
let empty = () => {};
(() => 'foobar')();
var simple = a => a > 15 ? 15 : a;
simple(16);
simple(10);
let max = (a, b) => a > b ? a : b;
var arr = [5, 6, 13, 0, 1, 18, 23];
var sum = arr.reduce((a, b) => a + b);
var even = arr.filter(v => v % 2 == 0);
var double = arr.map(v => v * 2);
promise.then(a => {
}).then(b => {
});
setTimeout( () => {
console.log('I happen sooner');
setTimeout( () => {
console.log('I happen later');
}, 1);
}, 1);
Example 3: arrow function javascript
function bob (a){
return a + 100;
}
let bob = a => a + 100;
Example 4: arrow function javascript
params => ({foo: "a"})