parent
96fe0a5439
commit
e9651c6afe
2 changed files with 17 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
To make an object immutable, you can use `Object.freeze()` method. It prevents the modification of existing property values and prevents the addition of new properties. |
||||||
|
|
||||||
|
```js |
||||||
|
const roadmap = { |
||||||
|
name: 'JavaScript', |
||||||
|
}; |
||||||
|
|
||||||
|
Object.freeze(roadmap); |
||||||
|
|
||||||
|
roadmap.name = 'JavaScript Roadmap'; // throws an error in strict mode |
||||||
|
console.log(roadmap.name); // JavaScript |
||||||
|
``` |
Loading…
Reference in new issue