JS Built-ins
FunctionalProgrammingintermediate

Pure function β€” referential transparency

πŸ“– Usage Example
function square(n) { return n * n; }
const result = square(4); // 16
// Anywhere you see square(4), you can replace it with 16

Referential transparency means you can replace a call with its return value everywhere.

Referential Transparency

A hallmark of pure functions is referential transparency: you can replace a function call with its return value without changing program behavior.

Challenge: Implement a pure multiply function and verify that calling it multiple times with the same inputs always produces identical results.

πŸ’‘ Hints (3)
  • β€’ Pure functions have no randomness
  • β€’ No reliance on external state
  • β€’ Outputs are completely predictable