Functional Programming in Javascript?

  • anonymous functions with closures
  • first-class functions
  • native map, reduce, filter,...

Quotes

I think the lack of reusability comes in object-oriented languages, not functional languages. Because the problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them... You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.”
- Joel Armstrong
“If you're creating constructor functions and calling new on them, you don't know javascript.” - Eric Elliot
“I now see my early attempts to support the classical model in JavaScript as a mistake.” - Douglas Crockford
“OO is the roman numerals of computing” - Rob Pike

Benefits of FP

  • Simpler code, less code.
  • Easier to test, better coverage.
  • Composable functions - building blocks for programs.

Object Oriented Programming

bundles state and logic together

state in lots of places

dependencies

Functional Programming

separates state and logic

  • higher order functions
  • state in one place

Example: OO / FP comparison

Let's capitalize each word in a sentence.

thanks!