Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

JavaScript is the first language to bring Functional Programming to the mainstream. It has first-class functions and closures. They open the way for functional programming patterns.

First-Class Functions

Functions are first-class objects. Functions can be stored in variables, objects or arrays, passed as arguments to other functions or returned from functions.

//stored in variable
function doSomething(){
}
//stored in variable
const doSomething = function (){ };
//stored in property
const obj = { 
   doSomething : function(){ } 
}
//passed as an argument
process(doSomething);
//returned from function
function createGenerator(){
  return function(){
  }
}

Lambdas

A lambda is a function that is used as a value.

In JavaScript, functions are first-class objects, so all functions can be used as values. All functions can be lambdas with or without a name. I actually suggest favoring named functions.

Functional Array Toolbox

Basic Toolbox

filter() selects values from a list based on a predicate function that decides what values should be kept.

const numbers = [1,2,3,4,5,6];
function isEven(number){
  return number % 2 === 0;
}
const evenNumbers = numbers.filter(isEven);

A predicate function is a function that takes one value as input and returns true/false based on whether the value satisfies the condition. isEven() is a predicate function.

Read Functional Architecture with React and Redux and learn how to build apps in function style.

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

For more on applying functional programming techniques in React take a look at Functional React.

You can find me on Medium and Twitter.