Skip to content

Commit c5873fe

Browse files
authored
How can we freeze an object
1 parent b2f9c88 commit c5873fe

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,36 @@ Object.is(foo, foo); // true
290290
Object.is(foo, bar); // false
291291
292292
```
293+
294+
295+
296+
# How can we freeze an object
297+
298+
299+
```javascript
300+
const obj = {
301+
name: "JSsnippets",
302+
age:29,
303+
address:{
304+
street : 'JS'
305+
}
306+
};
307+
308+
const frozenObject = Object.freeze(obj);
309+
310+
frozenObject.name = 'weLoveJS'; // Uncaught TypeError
311+
312+
//Although, we still can change a property’s value if it’s an object:
313+
314+
frozenObject.address.street = 'React'; // no error, new value is set
315+
316+
317+
delete frozenObject.name // Cannot delete property 'name' of #<Object>
318+
319+
320+
//We can check if an object is frozen by using
321+
Object.isFrozen(obj) //true
322+
323+
```
324+
325+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy