Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Referential transparency

In mathematics, referential transparency is the property that lets you replace an expression with its value without changing the results of whatever you were doing.

The counterpart of referential transparency is, appropriately enough, referential opacity. A referentially opaque function cannot guarantee that it will always produce the same result, even when called with the same arguments.

To give a simple example, let's consider what happens with an optimizing compiler that performs constant folding. Suppose you have a sentence like this:

const x = 1 + 2 * 3;

The compiler might optimize the code to the following by noting that 2 * 3 is a constant value:

const x = 1 + 6;

Even better, a new round of optimization could ...

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.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content