Skip to content

Commit 4610d3a

Browse files
Merge pull request #16 from moinuddin14/patch-1
Included Object.freeze() to freeze a const object
2 parents 07de969 + cc3c04e commit 4610d3a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ebook/01_var_let_const.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ In this case we are not reassigning the whole variable but just one of its prope
100100

101101
---
102102

103+
Note: We can still freeze the const object, which will not change the contents of the object (but trying to change the values of object Javascript will not throw any error)
104+
105+
``` javascript
106+
const person = {
107+
name: 'Alberto',
108+
age: 25,
109+
}
110+
111+
person.age = 26;
112+
console.log(person.age);
113+
// 26
114+
115+
Object.freeze(person)
116+
117+
person.age = 30;
118+
119+
console.log(person.age);
120+
// 26
121+
```
122+
103123
 
104124

105125
## The temporal dead zone

0 commit comments

Comments
 (0)