0 votes
in JavaScript by
Is this a pure function?
function sum(a, b) {
  return a + b;
}
  • A: Yes
  • B: No

1 Answer

0 votes
by

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.

...