I recently read this article, which explains in detail how to use functional programming techniques in JavaScript. It's well written, well-formatted, and correct. Unfortunately, it's also totally useless because the examples are total crap.

The author spends about 1000 words and a bunch of code snippets explaining how closures and currying work (without really using those terms). And then, he writes:

A Common Use-Case

Whether writing code just for yourself or presenting an API to your users, it's often helpful to create a more specialized function as a "wrapper" to a more generalized function if you expect to be performing a task repetitively. One way to do this would be to just define the functions manually.

Ooh! Use cases! Real-life examples! I'm finally going to learn where I should use closures, and best practices of when and when not to use them! Etcetera!

And then...

// More general function. 
function add( a, b ) {
  return a + b;
// More specific functions. 
function add1( b ) {
  return add( 1, b );
function add10( b ) {
  return add( 10, b );


This is the stock example used in every book, example, code snippet, and tutorial on closures. It makes me crazy. It's so utterly useless it's almost comical. People read these articles, totally understand how to add two numbers using functional programming, but have absolutely no idea how to do anything else. I know because I used to be one of those people, endeavoring to use closures but not knowing how.

If you want to teach somebody something, you need to show them something useful, something relatable. Adding two numbers is totally unrelatable because nobody ever writes a function to do it except idiots and students of poor computer science programs.

So, if you're writing an article on functional programming, please give examples of a r eal-life situation where you used functional programming to do something useful. function add1(a, b) has been pretty much completely played out.

And, so you don't think I'm a total hypocrite, I did a presentation on this exact subject some time ago featuring a real-life situation where I used closures. You can view it on SlideShare.