119k views
5 votes
What is a pure function? (Two statements)

a) It has no return value; it doesn't modify anything outside its scope
b) It always returns a value; it modifies variables outside its scope
c) It modifies variables outside its scope; it doesn't return a value
d) It always returns a value; it doesn't modify anything outside its scope

User Oba
by
7.7k points

1 Answer

0 votes

Final answer:

A pure function is a function that always returns a value and doesn't modify anything outside its scope. It is a mathematical concept used in programming.

Step-by-step explanation:

A pure function is a function that always returns a value and doesn't modify anything outside its scope. It is a mathematical concept used in programming to describe functions that have no side effects.

For example, a pure function that calculates the square of a number would take a number as input and return its square, without modifying any variables outside the function or producing any other side effects.

Pure functions are important in programming as they are predictable and easier to test. They can be reasoned about in isolation and can be used to build complex systems by composing them together.

User Zafer Onay
by
7.2k points