|
1 | 1 | # Functional Programming Javascript
|
| 2 | + |
| 3 | +Functional programming is a style that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. |
| 4 | + |
| 5 | +## Arrow Functions (Fat Arrows) |
| 6 | + |
| 7 | +Arrow functions create a concise expression that encapsulates a small piece of functionality. Additionally, |
| 8 | +arrows retain the scope of the caller inside the function eliminating the need of `self = this`. |
| 9 | + |
| 10 | +For example: |
| 11 | + |
| 12 | +```javascript |
| 13 | +// const multiply = function(x,y) { |
| 14 | +// |
| 15 | +return x * y; |
| 16 | +// } |
| 17 | +// Can be rewritten as: |
| 18 | +// const multiply = (x, y) => { return x * y }; |
| 19 | +// Since the function is a single expression return and braces are not |
| 20 | +needed. |
| 21 | +const multiply = (x, y) => x * y; |
| 22 | +console.log(multiply(5,10)) //50 |
| 23 | +``` |
0 commit comments