javascript arrow syntax code example
Example 1: arrow function javascript
function Welcome(){
console.log("Normal function");
}
const Welcome = () => {
console.log("Normal function");
}
Example 2: arrow function javascript
let myFunction = (arg1, arg2, ...argN) => expression
let myFunction = (arg1, arg2, ...argN) => {
statement(s)
}
let hello = (arg1,arg2) => "Hello " + arg1 + " Welcome To "+ arg2;
console.log(hello("User","Grepper"))
Example 3: 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 4: concise body arrow functions javascript
const plantNeedsWater = day => day === 'Wednesday' ? true : false;