DEV Community

loading...
Cover image for Javascript Questions

Javascript Questions

Esraa
・1 min read

Is this a pure function?

function sum(a, b) {
return a + b;
}

A: Yes
B: No

Answer: A

A pure function is a function that always returns the same result, if the same arguments are passed.

The sum function always returns the same result. If we pass 1 and 2, it will always return 3 without side effects. If we pass 5 and 10, it will always return 15, and so on. This is the definition of a pure function.

Discussion (1)

Some comments have been hidden by the post's author - find out more