DEV Community

Cover image for Functional Programming Part 1 – Intro to functional programming
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Functional Programming Part 1 – Intro to functional programming

In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. (WIKI)

Do you understand anything of it ? If not then I think we are then same! I also don’t understanding anything when I first read this meaning. What is mutable data ? or what is the meaning of this? Why it even used ?Let’s start will what is a mutable data ?

Mutable data means you can change this data. Like – suppose we’ve a variable a=5 and in later we change the value and put 10 in a by a=10.

But In functional programming, we don’t use mutable data. Instead we use immutable data. We can’t change a data after we declare it. In JavaScript we use – const for declare immutable data, which you can’t change!

Now do you know why we use functional programming ? Let me tell you the reasons

  • Improve modularity
  • Less code code redundancy
  • More easier to solve complex problems
  • More maintainable
  • More Efficiency & some more

If you are using JS and used features like map or reduce. Do you know one thing?

You’re already using the functional programming!

Do you like today’s topic ?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

Top comments (2)

Collapse
 
mjsarfatti profile image
Manuele J Sarfatti

Hi Muhammad and thank you for the article, however I have to highlight a possible mistake and source of confusion:

const does not guarantee immutability in JavaScript, but rather non-reassignability.

For example:

const a = "Hello world!"
a = 1975 // ❌ NOT allowed

But:

const Person = {
  name: "Susan",
  lastName: "Doe",
}
Person.name = "Kate" // ✔️ allowed
Collapse
 
nerdjfpb profile image
Muhammad Ali (Nerdjfpb)

Yes I understand this part! I forgot about the object part!