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