Skip to main content
100%

1.10 Pure functions

✓ Published0🌍 Public
DDDDDDanica
Last edited Jan 10, 2017
Created on Jan 10, 2017

This example demonstrates the concept of pure functions in JavaScript by comparing operations on arrays and age-checking functions. It shows how `slice()` preserves the original array, returning the same result each time, while `splice()` mutates the array, producing different outputs on repeated calls. The code also contrasts an impure `checkAge` function that relies on an external `minimum` variable against a pure version with the variable defined inside. Using CodePen’s built-in console, the visualization visually juxtaposes these behaviors, highlighting the benefits of cacheability, portability, and testability.

AI-generated description

Similar vizzes