Thursday, November 2, 2017

Convert to Lambda Style Function

function multiplyBy2(x) {
  return x * 2;
}
console.log(multiplyBy2(10));
> 20

Use the => (ie, rocket or fat arrow) syntax with the following rules:
1. remove the function keyword and use const (or let) instead
2. if only one parameter remove the parentheses
3. remove the curly brackets
4. remove the return keyword

const multiplyByTwo = number => number * 2;
console.log(multiplyByTwo(7));
> 14