0 votes
in JavaScript by
What are the different ways to make an object non-extensible in Javascript?

1 Answer

0 votes
by

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

  1. Object.preventExtensions
  2. Object.seal
  3. Object.freeze
var newObject = {};

Object.preventExtensions(newObject); // Prevent objects are non-extensible
Object.isExtensible(newObject); // false

var sealedObject = Object.seal({}); // Sealed objects are non-extensible
Object.isExtensible(sealedObject); // false

var frozenObject = Object.freeze({}); // Frozen objects are non-extensible
Object.isExtensible(frozenObject); // false
...