Object.preventExtensionsbeginner// Prevent new properties from being added
const obj = { a: 1 }
Object.preventExtensions(obj)
obj.b = 2 // silently ignored
Object.keys(obj) // β ['a']Use Object.preventExtensions() to lock an object so no new properties can be added, while still allowing modifications to existing ones.
After calling Object.preventExtensions(), you can verify the result with Object.isExtensible().
Challenge: Implement makeAndCheckNonExtensible(obj) that locks the object and returns whether it is now non-extensible.