DEV Community

Kurapati Mahesh
Kurapati Mahesh

Posted on

4 2

Javascript: Referential Transparency

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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

Thanks,

You can follow me here: https://twitter.com/urstrulyvishwak

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay