• 0

Getting started with Functional programming in javascript

This series of posts will train you how to use functional programming in javascript, which is the foundation of many modern javascript based frameworks.

This post is a pre-requisite for the following posts on key operations to manipulate the collections.

Traversing an array

If you were asked to print all the elements in an array, the IMPERATIVE way to solve this problem would be to use the for loop as shown below. In this approach, we have to specify how do we want to traverse the array.


As our goal is to process each element in the array, we can simply abstract this complexity using DECLARATIVE aka FUNCTIONAL way, using Array.prototype.forEach() method.


The declarative approach hides the complexity of how to traverse the array, so you can focus on what to do with each item

Further reading

Functional vs Imperative