Pure Functions In JavaScript

An engineer by profession and a JavaScript Lover by heart.
First and foremost, I love writing code. Ever since writing my first program in C and manipulating it to produce the desired output. I believe in the power of programming to transform and improve the lives of people around the world.
My curiosity levels are as fresh as when I was a child. I believe in eternal learning and deliberate effort as they are the only way to become the smartest in the room. I am a good timekeeper, always willing to learn new skills and use them in real-life problems.
An ambitious individual with a desire to succeed. A Cricket fanatic. A student who likes to take risks and does not shy away from experimenting with various combinations in life. Striving to do a lot. Wish me good luck ๐๐ผ
My primary interest is in Web Development and Mobile Application Development.
Tech Stack:- ReactJS, NextJS, NodeJS, MongoDB, GraphQL, Javascript Version Control:- Git, Gitlab
A function is known as pure functions if it passes two tests:
๐ฌ. ๐ฆ๐ฎ๐บ๐ฒ ๐ถ๐ป๐ฝ๐๐๐ ๐ฎ๐น๐๐ฎ๐๐ ๐ฟ๐ฒ๐๐๐ฟ๐ป ๐๐ฎ๐บ๐ฒ ๐ผ๐๐๐ฝ๐๐๐
๐๐ ๐ฎ๐บ๐ฝ๐น๐ฒ ๐ const add = (x, y) => x + y;
add(2, 4); // 6
So it will always ๐ฟ๐ฒ๐๐๐ฟ๐ป ๐๐ต๐ฒ ๐๐ฎ๐บ๐ฒ ๐ผ๐๐๐ฝ๐๐ ๐ถ๐ณ ๐๐ผ๐ ๐ฝ๐ฎ๐๐ ๐ฎ ๐ฎ๐ป๐ฑ ๐ฐ.
Nothing else affects the output.
๐ญ. ๐ก๐ผ ๐๐ถ๐ฑ๐ฒ-๐ฒ๐ณ๐ณ๐ฒ๐ฐ๐๐
The side effect is any interaction with the outside world from within a function. It should not produce any side effects like No mutating input, Http Calls, etc.
So the ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ถ๐๐ถ๐ผ๐ป ๐ผ๐ณ ๐ฝ๐๐ฟ๐ฒ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐ would be:
The function always returns the same result if the same arguments are pass. It does not depend on any state, or data, change during a programโs execution, and does not produce any observable side effects. It must only depend on its input arguments.
๐๐ ๐ฎ๐บ๐ฝ๐น๐ฒ ๐
const add = (x, y) => x + y;
add(2, 4); // 6
// It will always return the same output if you pass 2 and 4