mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-23 03:56:23 +00:00
34 lines
715 B
Markdown
34 lines
715 B
Markdown
---
|
|
id: fd131977-33f2-42cd-9a3b-46ffd58b9e43
|
|
title: JavaScript Object Mutability
|
|
---
|
|
|
|
# Description
|
|
|
|
With objects, there is a difference between having two references to the
|
|
same object and having two different objects that contain the same
|
|
properties.
|
|
|
|
# Examples
|
|
|
|
``` javascript
|
|
let object1 = {value: 10};
|
|
let object2 = object1;
|
|
let object3 = {value: 10};
|
|
|
|
console.log(object1 == object2); // true
|
|
console.log(object1 == object3); // false
|
|
|
|
object1.value = 15;
|
|
console.log(object2.value); // 15
|
|
console.log(object3.value); // 10
|
|
```
|
|
|
|
\`const\` objects can have their values changed
|
|
|
|
``` javascript
|
|
const score = { visitors: 0, home: 1 };
|
|
score.visitors = 23;
|
|
|
|
console.log(score); // { visitors: 23, home: 1 }
|
|
```
|