Master the JavaScript Interview: What is Functional Programming?
- Pure functions
- Given the same inputs, always returns the same output, and
- Has no side-effects
- Function composition
- composition over imperative flow control
- Avoid shared state
- Pure functions instead of shared state & side effects
- Avoid mutating state
- Immutability over mutable data
- Avoid side effects
- Modifying any external variable or object property (e.g., a global variable, or a variable in the parent function scope chain)
- Logging to the console
- Writing to the screen
- Writing to a file
- Writing to the network
- Triggering any external process
- Calling any other functions with side-effects
- higher order function
- Lots of generic, reusable utilities that use higher order functions to act on many data types instead of methods that only operate on their colocated data
- Containers, Functors, Lists, and Streams
- Containers & higher order functions over ad-hoc polymorphism
- Declarative vs Imperative
- Imperative
- the flow control: How to do things.
- A statement is a piece of code which performs some action. Examples of commonly used statements include
for,if,switch,throw, etc…
- Declarative
- describing the data flow: What to do.
- An expression is a piece of code which evaluates to some value
- Imperative