Defines a property on an object with optional configuration
name of the property
value
Optional
target
const obj = {};defineProperty(obj, 'name', 'John');console.log(obj.name); // 'John'// With optionsdefineProperty(obj, 'age', 25, { writable: false });obj.age = 30; // Will not change the valueconsole.log(obj.age); // 25 Copy
const obj = {};defineProperty(obj, 'name', 'John');console.log(obj.name); // 'John'// With optionsdefineProperty(obj, 'age', 25, { writable: false });obj.age = 30; // Will not change the valueconsole.log(obj.age); // 25
Defines a property on an object with optional configuration