Arguments are passed by value, unless their value is an object, then they're passed by reference. birthYear
is passed by value, since it's a string, not an object. When we pass arguments by value, a copy of that value is created (see question 46).
The variable birthYear
has a reference to the value "1997"
. The argument year
also has a reference to the value "1997"
, but it's not the same value as birthYear
has a reference to. When we update the value of year
by setting year
equal to "1998"
, we are only updating the value of year
. birthYear
is still equal to "1997"
.
The value of person
is an object. The argument member
has a (copied) reference to the same object. When we modify a property of the object member
has a reference to, the value of person
will also be modified, since they both have a reference to the same object. person
's name
property is now equal to the value "Lydia"