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
Top comments (0)