Book Image

Mastering JavaScript Functional Programming - Second Edition

By : Federico Kereki
Book Image

Mastering JavaScript Functional Programming - Second Edition

By: Federico Kereki

Overview of this book

Functional programming is a paradigm for developing software with better performance. It helps you write concise and testable code. To help you take your programming skills to the next level, this comprehensive book will assist you in harnessing the capabilities of functional programming with JavaScript and writing highly maintainable and testable web and server apps using functional JavaScript. This second edition is updated and improved to cover features such as transducers, lenses, prisms and various other concepts to help you write efficient programs. By focusing on functional programming, you’ll not only start to write but also to test pure functions, and reduce side effects. The book also specifically allows you to discover techniques for simplifying code and applying recursion for loopless coding. Gradually, you’ll understand how to achieve immutability, implement design patterns, and work with data types for your application, before going on to learn functional reactive programming to handle complex events in your app. Finally, the book will take you through the design patterns that are relevant to functional programming. By the end of this book, you’ll have developed your JavaScript skills and have gained knowledge of the essential functional programming techniques to program effectively.
Table of Contents (17 chapters)
Technical Requirements

To get the most out of this book

To understand the concepts and code in this book, you don't need much more than a JavaScript environment and a text editor. To be honest, I even developed some of the examples working fully online, with tools such as JSFiddle (at and the like, and absolutely nothing else.

In this book, we'll be using ES2019, Node 13, and the code will run on any OS such as Linux, Mac OSX, or Windows; please do check the Technical Requirements section, for some other tools we'll also work with.

Finally, you will need some experience with the latest version of JavaScript, because it includes several features that can help you write more concise and compact code. We will frequently include pointers to online documentation, such as the documentation available on the Mozilla Development Network (MDM) at, to help you get more in-depth knowledge.

Download the example code files

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Let's review our once() function."

A block of code is set as follows:

function newCounter() {
let count = 0;
return function() {
return count;

const nc = newCounter();
console.log(nc()); // 1
console.log(nc()); // 2
console.log(nc()); // 3

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

function fact(n) {
if (n === 0) {
return 1;

} else {
return n * fact(n - 1);

console.log(fact(5)); // 120

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select the EXPERIMENTAL option to fully enable ES10 support."

Warnings or important notes appear like this.
Tips and tricks appear like this.