A Taste of Functional JavaScript

I’m back again! I haven’t done much on this project yet, but at least I did some web development work with a coworker – paid work! Woohoo! And this morning I worked with a friend on some great practice problems that teach functional programming in JavaScript.

But what is functional programming? I still don’t know. Wikipedia’s definition gives a clue, but it isn’t exactly beginner-friendly:

functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.”

My takeaway is this: functional programming is all about scary math stuff. Haha, OK, maybe I understand a bit more than that. But I don’t know how to express what I understand yet, because it’s all very fuzzy.

But here are some cool JavaScript methods that I learned how to use today, and apparently they’re important in writing functional JavaScript:

  • map() runs a provided function on every element of an array, creating a new array with the modified elements.
  • filter() checks if each element in an array meets certain criteria and creates a new array containing the elements that passed the test.
  • apply() calls a function with a given thisvalue and an array of arguments.

The short descriptions above don’t really do those methods justice. They’re incredibly powerful once you start using them, and I highly recommend this tutorial for anyone who’s interested!

I wanted to write about what I learned today in detail because I feel like I absorbed a lot of information, but I don’t know how to explain any of it yet. It’s still percolating. Isn’t it interesting how confusion seems to be an integral part of the learning process? I’m still in that stage where I’m feeling really stupid, but I know it means I’m making progress because I’m tackling concepts that are beyond my comfort zone.

But I still feel bad that I got derailed from what was supposed to be my main project this week – especially after vowing to focus on HTML and CSS instead of JavaScript! But I just can’t seem to stay away from JavaScript. So, I’ll cut myself some slack. Maybe I allow myself one or two JavaScript days each week, and I aim to spend the other five days on HTML and CSS and starting a freelance web design business. Tomorrow I hope to devote a solid 3 hours or more to working on HTML and CSS stuff to create the website for my meetup group.