|
91 | 91 | | 84 | [How can you assign default values to variables](#84-how-can-you-assign-default-values-to-variables) |
|
92 | 92 | | 85 | [How to determine if an object is extensible or not](#85-how-to-determine-if-an-object-is-extensible-or-not) |
|
93 | 93 | | 86 | [In how many ways we can make an object non-extensible](#86-in-how-many-ways-we-can-make-an-object-non-extensible) |
|
| 94 | +| 87 | [What is object.freeze method](#87-what-is-objectfreeze-method) | |
| 95 | +| 88 | [What is object.seal method](#88-what-is-objectseal-method) | |
94 | 96 |
|
95 | 97 | ### 1. What is JavaScript
|
96 | 98 | * JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
|
@@ -1255,6 +1257,41 @@ console.log(Object.isExtensible(obj1)); // output ========> true
|
1255 | 1257 |
|
1256 | 1258 | **[:top: Scroll to Top](#javascript-interview-questions)**
|
1257 | 1259 |
|
| 1260 | +### 87. What is object.freeze method |
| 1261 | +- Object.freeze makes the object immutable |
| 1262 | +- Can not add new properties to existing object |
| 1263 | +- Can not delete or modify existing properties |
| 1264 | + |
| 1265 | +```js |
| 1266 | +const obj = { |
| 1267 | + property1: 'value 1', |
| 1268 | + property2: 'value 2', |
| 1269 | +}; |
| 1270 | +Object.freeze(obj); |
| 1271 | +obj.property1 = 'new value'; // This will not modify the existing property |
| 1272 | +obj.property3 = 'value 3'; // This will not add new property to the object |
| 1273 | +console.log(obj); // output ========> { property1: "value 1", property2: "value 2" } |
| 1274 | +``` |
| 1275 | + |
| 1276 | +**[:top: Scroll to Top](#javascript-interview-questions)** |
| 1277 | + |
| 1278 | +### 88. What is object.seal method |
| 1279 | +- Object.seal makes the object immutable |
| 1280 | +- Can not add new properties or delete existing properties |
| 1281 | +- Can modify existing properties. |
| 1282 | +```js |
| 1283 | +const obj = { |
| 1284 | + property1: 'value 1', |
| 1285 | + property2: 'value 2', |
| 1286 | +}; |
| 1287 | +Object.seal(obj); |
| 1288 | +obj.property1 = 'new value'; // This will modify the existing property |
| 1289 | +obj.property3 = 'value 3'; // This will not add new property to the object |
| 1290 | +console.log(obj); // output ========> { property1: "new value", property2: "value 2" } |
| 1291 | +``` |
| 1292 | + |
| 1293 | +**[:top: Scroll to Top](#javascript-interview-questions)** |
| 1294 | + |
1258 | 1295 | ## Output Based Questions
|
1259 | 1296 |
|
1260 | 1297 | **1. What will be the output**
|
|
0 commit comments