1+ /*
2+ Javascript Object.isFrozen()
3+ The JavaScript Object.isFrozen() checks if an object is frozen.
4+
5+ A frozen object can no longer be changed. Freezing an object prevents:
6+
7+ New properties from being added to the object.
8+ Existing properties to be removed from the object.
9+ Changing the enumerability, configurability, or writability of existing properties.
10+ Changing values of the existing object properties and prototype.
11+ The syntax of the isFrozen() method is:
12+
13+ Object.isFrozen(obj)
14+ The isFrozen() method, being a static method, is called using the Object class name.
15+
16+ isFrozen() Parameters
17+ The isFrozen() method takes in:
18+
19+ obj - The object which should be checked.
20+ Return value from isFrozen()
21+ Returns a Boolean indicating whether or not the given object is frozen.
22+ Example: Using isFrozen()
23+ // new objects are extensible, so not frozen
24+ console.log(Object.isFrozen({ name: "JavaScript" })); // false
25+
26+ // preventing extensions only does not make frozen
27+ // property is still configurable
28+ let obj = { a: 1 };
29+ Object.preventExtensions(obj);
30+ console.log(Object.isFrozen(obj)); // false
31+
32+ // deleting property
33+ delete obj.a;
34+ console.log(Object.isFrozen(obj)); // true -> vacuously frozen
35+
36+ let newObj = { b: 2 };
37+ // make non-extensible
38+ Object.preventExtensions(newObj);
39+ // make non-writable
40+ Object.defineProperty(newObj, "b", {
41+ writable: false,
42+ });
43+ // properties are still configurable
44+ console.log(Object.isFrozen(newObj)); // false
45+
46+ // using freeze()
47+ let frozen = { 65: "A" };
48+
49+ Object.freeze(frozen);
50+ console.log(Object.isFrozen(frozen)); // true
51+
52+
53+
54+
55+
56+
57+ */
0 commit comments