DEV Community

Cover image for Functional programming.js
Tajeddine Alaoui
Tajeddine Alaoui

Posted on • Updated on

Functional programming.js

Functional programming it's not a language, It's a paradigm (style of programming).

So what are the perks of functional programming ?

  • Immutability (const variable instead of var/let)
  • Higher-order functions (functions passed around as variables)
  • Recursion (when a function calls itself)

And many more...

When is functional programming usually used

  • Data processing
  • Serverless
  • High-Criticality systems

The best part that i like about it is that it's really consice (short code) and robost compared to oop for instance.

Her's an example of functional programming code

function getOdds2(arr){
   return arr.filter(num => num % 2 !== 0)
}
console.log(getOdds2(arr))
// logs [ 1, 3, 5, 7, 9 ]
// this can be even shorter
const getOdds3 = arr => arr.filter(num => num % 2 !== 0)
console.log(getOdds3(arr))
// logs [ 1, 3, 5, 7, 9 ]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)