Objects are mutable: They are passed by reference, not by value.
If person
is an object, the following statement will not create a copy of person
:
const x = person; |
The object x
is not a copy of person
; it is person
.
Both x
and person
refer to the same memory address.
Any modifications made to x
will also affect person
:
Example
//Create an Object const person = { firstName:“John”, lastName:“Doe”, age:50, eyeColor:“blue” } // Create a copy const x = person; // Change Age in both x.age = 10; |