JS is:
- Functional*
- OOP
- ...
Code style, Mindset
- Computation as the evaluation of mathematical functions
- Avoid changing-state and mutable data
- ...
-
Pure function
-
Same input => Same output
-
No side effect
-
This is not a pure function
var absolute_zero = -273.15; const celsiusToKelvin = (temp) => { return temp - absolute_zero; };
-
This is cool
const celsiusToKelvin = (temp, absolute_zero) => { return temp - absolute_zero; }; // OR const celsiusToKelvin = (temp) => { return temp + 273.15; };
-
-
Immutability
-
High order function