File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -290,3 +290,36 @@ Object.is(foo, foo); // true
290290Object.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+
You can’t perform that action at this time.
0 commit comments