forked from Safnaj/JavaScript-ES6
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfreeze.js
More file actions
29 lines (22 loc) · 630 Bytes
/
freeze.js
File metadata and controls
29 lines (22 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
let obj = {"country" : ""};
obj.country = "Sri Lanka";
Object.freeze(obj); //if its freezed it wont change the object value.
console.log(obj);
obj.country = "USA";
console.log(obj);
// Ex 2
//Object Freeze function will only freeze the first level objects.
let flower = {
name: "",
price: {
t1: 10,
tr: 20
}
}
flower.name = "Rose";
flower.price.t1 = 25;
console.log(flower); // {name : 'Rose', price {t1: 25, t2: 20 }}
Object.freeze(flower);
flower.name = "Lotus";
flower.price.t1 = 15;
console.log(flower); // {name : 'Rose', price {t1: 15, t2: 20 }} //Freeze wont work for second level values.