Object.preventExtensionsintermediate// 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.
In strict mode, attempting to add a property to a non-extensible object throws a TypeError. In sloppy mode, it silently fails.
Challenge: Verify that adding a property to a non-extensible object silently fails in sloppy mode (does not add the property).