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.
Top comments (0)
Some comments have been hidden by the post's author - find out more