The following list of features is frequently used to attribute the functional languages:
- Higher-order functions - the functions that take other functions as their arguments;
- Purity - absence of side effects;
- Recursion - availability of tail-call optimisation.
reduce, etc) eliminated necessity of mutating loop counter (index) to go through the lists.
const added concept of "readonly" variables. Readonly properties made immutable records possible. Generators and improved iterators provided a way to create immutable iterable data sets. The most recent addition to the set of functional features is optimisation of tail recursion, now available in some of JS engines.
Although it was possible to create pure functions in earlier JS versions, the recent additions to the language added methods to create immutable data structures and provided ways to avoid using mutable variables for basic operations.
// toInt is a pure function that converts strings // to integers. It does it by partially applying // parseInt function, fixing its second argument. let toInt = x => parseInt(x, 10); // apply is a high-order pure function let apply = (f, x) => f(x); // it applies the first argument to the second apply(toInt, "16"); // 16 (integer)
Functional programming, https://wiki.haskell.org/Functional_programming ↩︎
Functional programming, https://en.wikipedia.org/wiki/Functional_programming ↩︎
ES6 In Depth: Arrow functions, https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/ ↩︎
ECMAScript 6 Proper Tail Calls in WebKit, https://webkit.org/blog/6240/ecmascript-6-proper-tail-calls-in-webkit/ ↩︎