Object-Oriented Programming and Functional Programming are two very distinct programming paradigms with their own rules and their own pros and cons.

However, JavaScript, instead of following one all the way down is sitting right in the middle of the two giving you some aspects of what a normal OOP language would have such as classes, objects, inheritance, and the like. But at the same time, it also provides you with some concepts of Functional Programming, such as higher-order functions and the ability to compose them as well.

So, while our favorite little language isn’t fully functional, I wanted to cover some of its aspects and how to use them to your advantage in JavaScript.


Tip: Use Bit (Github) to share, document, and manage reusable JS components from different projects. It’s a great way to increase code reuse, speed up development, and build apps that scale.

The shared component cloud

Bit is a scalable and collaborative way to build and reuse components. It’s everything you need from local development…

bit.dev


Higher-Order Functions

Let’s start by the most important of the three concepts I’m covering in this article: Higher Order Functions.

Having access to higher-order functions means functions are more than a construct you can define and call from your code, in fact, you can use them as assignable entities.

This should not come in as a surprise if you’ve done some JavaScript, after all, you should’ve been able to assign anonymous functions to constants simply from following examples online. Something like this is extremely common:

const adder = (a, b) => {
	  return a + b
	}
view raw
simple-fn-assign.js hosted with ❤ by GitHub

What might come as a surprise, especially if JavaScript is what you used to learn programming, is that the above logic is not valid in many other languages. Being able to assign a function as you would an integer is a very useful tool to have, in fact, most of the topics covered in this article are a by-product of that.

#web-development #functional-programming #programming #nodejs #javascript #function

 Functions, Composition and Currying
1.25 GEEK