Learning Javascript, LHS RHS

RHS and LHS are a bit confusing to me.

I can understand how this works what it does but, just can’t grasp the grouping this into RHS and LHS. I can understand The engine, complier, and scope tasks from the book. Any tips for LHS and RHS ?
function foo(a) { var b = a; return a + b; } var c = foo( 2 );

1 Like

Think of it like this

LHS = Variable assignment, or writing to memory. Think saving a text file to your hard drive.
RHS = Variable lookup, or reading from memory. Think opening a text file from your hard drive.

So, var b is LHS because the engine wants to write something to memory. Then the a is RHS because it wants to get that value from memory.

I hope that helps.

// first, we have a function 'foo' with the parameter 'a'
function foo (a) { // and, when we run this function ....
// it creates the variable 'b', and the value that has a parameter 'a' (2), assign to variable 'b' 
var b = a; // 'b' becomes 2
// then, it returns the sum of these two values ( 'a' and 'b' or 2 and 2 in this case )
return a + b;
// assign a value that returns a function 'foo' with the parameter '2' to variable 'c'
var c = foo (2);

Try this code:


We can embed runnable code in the forum now!