lambda expression js code example
Example 1: js lambda
function (a, b){
return a + b + 100;
}
(a, b) => a + b + 100;
let a = 4;
let b = 2;
function (){
return a + b + 100;
}
let a = 4;
let b = 2;
() => a + b + 100;
Example 2: Arrow Functions
const magic = function() {
return new Date();
};
const magic = () => {
return new Date();
};
const magic = () => new Date();
Example 3: () => javascript
var a = [
"We're up all night 'til the sun",
"We're up all night to get some",
"We're up all night for good fun",
"We're up all night to get lucky"
];
var a2 = a.map(function (s) { return s.length });
var a3 = a.map( s => s.length);
Example 4: es6 arrow function
const prices = smartPhones.map(smartPhone => smartPhone.price);
console.log(prices);