[javascript] operators

Hi there,
in this exercise of operator, ‘c’ is not supposed to be blue since a = b?

The value should be red.

You instantiate a and b
then c from a
So c has the value of a

Then you change the value of a which is independent from c.

The way you are thinking of it is called “by reference” but it is “by value”.

Chronologically it goes something like this:

a b c Instruction
‘red’ let a = 'red'
‘red’ ‘blue’ let b = 'blue'
‘red’ ‘blue’ ‘red’ let c = a
‘blue’ ‘blue’ ‘red’ a = b


1 Like

That is a heck of an explanation :grinning:.
So when I initially assign the variable c to the value of a, c won’t be affected when I later change the value of a for b?

You can read those articles:

Primitive and Reference value in JavaScript @G4G
Pass by Value and Pass by Reference in Javascript @G4G