JS: Object .preventExtensions 👎

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

🟢 tip: better is Reflect.preventExtensions.

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