-
Notifications
You must be signed in to change notification settings - Fork 0
Functional Programming in JavaScript
Largely based on a reading of the article Functional Programming in JavaScript — With Practical Examples (Part 1) by Raja Rao DV
Functional Programming (or "FP") refers to a methodology where you modularize your program as much as possible by making a series of single-purpose functions. The article referenced above puts it best:
Functional Programming is a style of writing programs by simply composing a set of functions.
Essentially, FP asks us to wrap virtually everything in functions, write lots of small reusable functions and simply call them one after the other to get the result like: (func1.func2.func3) or in a compose fashion, like: func1(func2(func3())).
FP also emphasizes not changing the values that you pass into functions. You'll see this said like "a function that takes in an array and reverses it without mutating the original input array (so we can reference it later)".
JavaScript is not a purely functional programming language (like Haskell), but JS has enough built-in to mimic the behavior of a purely FP language. If you were to build these FP behaviors in JavaScript, you could put them in a library that you can reference in your programs. (Hint, hint: there are some nifty JS libraries out there that do exactly this).
This article won't dive into the details, but here are a few of the big Functional Programming concepts/tools you can google for more info:
- Currying
- Pure Functions
- “Fantasy-land” specs
- “Functors”
- “Monads”
- “Maybe Monads”
- “Either Monads”
- inheritance
- ydkjs - objects
- eloquent js - functional programming
- functional programming in js - fcc
- mdn new
- mdn inheritance and prototype chain
- mdn this
- javascript context tutorial
- Bookmark
- node error docs
- mdn object prototype
- mdn class
All wiki pages are summaries of the work of others. See the top of each page for the source blogs/articles/books and their authors. All other content by Billy Bunn.