My Explanation of Functional Programming?

Keenan Jones
2 min readAug 20, 2020

“Functional programming is the process of building software by composing pure functions. A programming paradigm where programs constructed by applying and composing functions.” Let’s begin by destructing these to sentences shall we?

First a little background and reading recommendations. Javascript allows multiple paradigms to be use: object-oriented, procedural, and functional paradigm. Great resources I reference for this article are “Master the JavaScript Interview: What is Functional Programming?” by Eric Elliot and “Functional Programming Principles in Javascript” by TK on Free Code Camp. gratitude to these dudes.

What is a programming paradigm, right? My understanding of programming paradigms is coding with some fundamental and defining principles in mind. Such as object oriented programming, coding centered around creating and interacting with objects. Keep objects in mind while coding.

Functional programming is developing software with functions as a priority. Okay, we know what functions are right. What kind of functions you ask? Well, pure functions which are functions that always return the same output with the same input. I think it’s more informative to explain what pure functions are not rather what they are. Pure functions do not interact with any variables, objects or memory space that exist in a property of an object being passed between scopes. Let’s put a pin in this idea of scope. Functional programming relies on expressions, or a piece of code which evaluates to some value. That’s the most zoom in I can get with Functional Programming but, let’s go back to scopes. A Closure is the combination of a function enclosed with reference to its surrounding state. Closures are important to Javascript’s functional programming because it allows each function to keep their inner workings private, remember doesn’t effect external states.

function init() {
var name = 'Mozilla'; // name is a local variable created by init
function displayName() { // displayName() is the inner function, a closure
alert(name); // use variable declared in the parent function
}
displayName();
}
init();

When using the functional paradigm, it creates code that is independent in nature, easy to move around, reorganize and refactor. All are ways to mature as a developer. I hope this post will help you while on your coding journey. Thanks for reading.

--

--