01 Functional Programming in Javascript.

abhishekkrpand1

Karma7

Posted on May 11, 2024

01 Functional Programming in Javascript.

I am going to write a series of blogs on functional Programming in Javascript.

Javascript has the most important features needed for Functional Programming.

1. First class function- In JavaScript, you can treat functions like regular data. This means you can pass functions around as if they were just variables, give them as inputs to other functions, get them back as outputs from functions, and even store them in variables or inside objects. This feature lets you create what are called "higher-order functions," which can do cool things like filling in some function arguments for you (partial application), breaking functions into smaller parts (currying), and combining functions together (composition).

2. Anonymous Function- Arrow function or lambda function it makes easier to work with the Higher order function.

 a => a * a
Enter fullscreen mode Exit fullscreen mode

3. Closure- Closures are created at a function creation time. Closures are how partial applications get their fixed Arguments.

Whats Javascript missing to be a Functional Programming

JavaScript is a multi-paradigm language, meaning it supports programming in different styles. However, the disadvantage of this is that imperative programming, for example, tends to imply that almost everything needs to be mutable.

const foo = {
  bar : 'baz'
}
foo.bar = 'wow'
Enter fullscreen mode Exit fullscreen mode

the object properties are mutable so that object can modify them.
1. Purity- In some Functional Programming language purity is enforced by default, any expressions which contains side-effects are not allowed.

2. Immutability- In some fp language you can't mutate the data directly, you have to return a data each time.

In upcoming blogs we will discuss about the Pure functions in depth.

Happy Learning!!

💖 💪 🙅 🚩
abhishekkrpand1
Karma7

Posted on May 11, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related