DEV Community

Himanshu Kanojiya
Himanshu Kanojiya

Posted on

Short Note about Functional Programming in JavaScript

Functional programming is programming paradigms where we take care of multiple things like:

  1. Each operation decomposes into multiple functions. For example, a Function should perform one task.
  2. Function should be pure and will always take input and give an output.
  3. Side effects operation should be encapsulated into another function that is only responsible to handle/perform side effects and should be not mixed with regular operations.
  4. Immutability, where the function should not change the global data or passed references of arrays and objects (non-primitive values). Instead, make a copy of that data and use it. Like map, filter, and forEach higher-order function.
  5. Function composition, where one function output becomes the output of another function.

Top comments (2)

Collapse
 
ssimontis profile image
Scott Simontis

Would you mind sharing some examples about how these concepts have helped you write better code? I do agree they are powerful concepts!

Collapse
 
himanshukanojiya profile image
Himanshu Kanojiya

Sure, I will add some code example's for each point