JS: Object.preventExtensions ❌

By Xah Lee. Date: . Last updated: .
Object.preventExtensions(obj)
  • Make obj not extensible.
  • Return obj.
  • No error if obj is not a object type.

🟢 TIP: use Reflect.preventExtensions instead.

// make an object not extensible
const jj = {};
Object.preventExtensions(jj);
console.assert(Object.isExtensible(jj) === false);
// no error if arg is not object
console.assert(Object.preventExtensions(3) === 3);

JavaScript. Prevent Change Property