Pure functions
FP introduces some concepts and principles that will help us to improve the predictability of our code. Let's look at one of these core concepts: pure functions.
A function can be considered pure when it returns a value computed using only the arguments passed to it. Also, a pure function avoids mutating its arguments or any other external variables. As a result, a pure function always returns the same value given the same arguments, independently of when it is invoked.
The isIndexPage function declared in the preceding section is not a pure function because it accesses the pathname variable and it has not been passed as an argument to the function. We can transform the preceding function into a pure function by rewriting it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access