Introducing Functional Programming with Underscore.js

How can you overcome JavaScript language oddities and unsafe features? With this book, you’ll learn how to create code that’s beautiful, safe, and simple to understand and test by using JavaScript’s functional programming support. Author Michael Fogus shows you how to apply functional-style concepts with Underscore.js, a JavaScript library that facilitates functional programming techniques. Sample code is available on GitHub at

Fogus helps you think in a functional way to help you minimize complexity in the programs you build. If you’re a JavaScript programmer hoping to learn functional programming techniques, or a functional programmer looking to learn JavaScript, this book is the ideal introduction.

  • Use applicative programming techniques with first-class functions
  • Understand how and why you might leverage variable scoping and closures
  • Delve into higher-order functions—and learn how they take other functions as arguments for maximum advantage
  • Explore ways to compose new functions from existing functions
  • Get around JavaScript’s limitations for using recursive functions
  • Reduce, hide, or eliminate the footprint of state change in your programs
  • Practice flow-based programming with chains and functional pipelines
  • Discover how to code without using classes

Michael Fogus

Michael Fogus is software developer with experience in distributedsimulation, machine vision, and expert systems construction. He's actively involved in the Clojure and Scala communities.

  1. Chapter 1 Introducing Functional JavaScript

    1. The Case for JavaScript

    2. Getting Started with Functional Programming

    3. The Case for Underscore

    4. Summary

  2. Chapter 2 First-Class Functions and Applicative Programming

    1. Functions as First-Class Things

    2. Applicative Programming

    3. Data Thinking

    4. Summary

  3. Chapter 3 Variable Scope and Closures

    1. Global Scope

    2. Lexical Scope

    3. Dynamic Scope

    4. Function Scope

    5. Closures

    6. Summary

  4. Chapter 4 Higher-Order Functions

    1. Functions That Take Other Functions

    2. Functions That Return Other Functions

    3. Putting It All Together: Object Validators

    4. Summary

  5. Chapter 5 Function-Building Functions

    1. The Essence of Functional Composition

    2. Currying

    3. Partial Application

    4. Stitching Functions End-to-End with Compose

    5. Summary

  6. Chapter 6 Recursion

    1. Self-Absorbed Functions (Functions That Call Themselves)

    2. Codependent Functions (Functions Calling Other Functions That Call Back)

    3. Too Much Recursion!

    4. Recursion Is a Low-Level Operation

    5. Summary

  7. Chapter 7 Purity, Immutability, and Policies for Change

    1. Purity

    2. Immutability

    3. Policies for Controlling Change

    4. Summary

  8. Chapter 8 Flow-Based Programming

    1. Chaining

    2. Pipelining

    3. Data Flow versus Control Flow

    4. Summary

  9. Chapter 9 Programming Without Class

    1. Data Orientation

    2. Mixins

  10. Appendix Functional JavaScript in the Wild

    1. Functional Libraries for JavaScript

    2. Functional Programming Languages Targeting JavaScript

  11. Appendix Annotated Bibliography

    1. Papers/Books/Blog Posts/Talks

    2. Presentations

    3. Blog Posts

    4. Journal Articles

  12. Colophon