This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Mahesh
An expression in javascript can be replaced by its value is called referential transparency.
const add = (x,y)=>x + y;
const multiply = (x)=>x * 4;
// add (3, 4) can be replaced by 7. - Referential Transparency.
multiply(add(3, 4));
> 28
multiply(add(3, 4));
> 28
const arr = [];
const add = (x,y)=>{
const addition = x + y;
arr.push(addition);
return addition;
}
const multiply = (x)=>x * 4;
// Here, we can't replace add(3,4) with 7 as it affects the program
multiply(add(3, 4));
> 28
> multiply(add(3, 4));
28
Thanks,
You can follow me here: https://twitter.com/urstrulyvishwak
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Mahesh

Mahesh | Sciencx (2022-09-14T18:26:41+00:00) Javascript: Referential Transparency. Retrieved from https://www.scien.cx/2022/09/14/javascript-referential-transparency/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.