JS Coding Questions Logo
JS Coding Questions
#264💼 Interview💻 Code

What are the different ways to make an object non-extensible

Advertisement

728x90

You can mark an object non-extensible in 3 ways,

1. Object.preventExtensions

2. Object.seal

3. Object.freeze

javascript
1var newObject = {};
2
3Object.preventExtensions(newObject); // Prevent objects are non-extensible
4
5Object.isExtensible(newObject); // false
6
7var sealedObject = Object.seal({}); // Sealed objects are non-extensible
8
9Object.isExtensible(sealedObject); // false
10
11var frozenObject = Object.freeze({}); // Frozen objects are non-extensible
12
13Object.isExtensible(frozenObject); // false

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 7

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
264of476
What are the different ways to make an object non-extensible | JSCodingQuestions.com