Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions or declarations instead of statements. In functional programming, the output value of a function depends only on its arguments, so calling a function with the same value for an argument always produces the same result. This is in contrast to imperative programming, where the program state may change during the computation.

Functional programming in JavaScript

In JavaScript, functions are first-class objects. This means that functions can be used like any other object. They can be stored in variables, arrays, and objects. They can be passed as arguments to other functions, and functions can be returned from other functions. Functions can have properties and methods just like any other object. JavaScript also supports higher-order functions, which means that you can use functions as arguments to other functions, or return a function from another function. But its not enough to be a functional programming language.

Here are some libraries that can help you write functional code in JavaScript in a more declarative way.

Ramda

Ramda is excellent library which provide functional flavor. It emphasizes a pure function, immutability. Its provide range of utility function for functional programming which are automatically curried.

It is a excellent library and is well maintained. It is also very popular and has a large community. It is also very well documented.

Here are some articles that can help you get started with Ramda.

Lodash

Lodash is a JavaScript utility library delivering consistency, modularity, performance, & extras. It is a very popular library and has a large community. It is also very well documented.

Why Lodash?

Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc. Lodash’s modular methods are great for:

Iterating arrays, objects, & strings Manipulating & testing values Creating composite functions

Underscore

Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

Underscore provides over 100 functions that support both your favorite workaday functional helpers: map, filter, invoke — as well as more specialized goodies: function binding, javascript templating, creating quick indexes, deep equality testing, and so on.

Sugar

Sugar is a JavaScript library that extends the built-in objects to provide a more consistent, powerful, and friendly API. It is a very popular library and has a large community. It is also very well documented.

Lazy.js

Lazy.js is a functional utility library for JavaScript, similar to Underscore and Lodash, but with a lazy engine under the hood that strives to do as little work as possible while being as flexible as possible

preludejs

preludejsis a modular implementation of Haskell’s Prelude library in ES6

Maybe you don’t need library?

Above mention library are great JS functional programming library. However, when you are targeting modern browsers, you may find out that there are many methods which are already supported natively thanks to ECMAScript5 [ES5] and ECMAScript2015 [ES6].

You-Dont-Need-Lodash-Underscore is an excellent resource that shows you how to use native JavaScript methods instead of using Lodash or Underscore.