We will learn through real examples how Functional Programming can provide a better approach than Object Oriented Programming- in some situations that we are currently dealing with.
In JavaScript we can choose to use either of the OOP or FP paradigms as much, or as little, as we like. So, what is Functional Programming in a nutshell?
- Immutable Data
Immutable data cannot be changed once created, leading to much simpler development and easier reasoning of app state.
- Pure functions
A pure function is a function that, given the same input, will always return the same output, does not have any observable side effects and does not rely on any external state.
All this is possible because in JavaScript functions are first-class citizens. This means functions are objects (of the type Object
), and, therefore, can be assigned as the value of a variable. The ability to use higher-order functions -a function that takes a function as an argument or that returns a function as a result- makes JavaScript a suitable language for functional programming.
- First round
- Second round
- Third round