Defines a non-writable and non-configurable property
name of the property
value
Optional
target
const obj = {};defineConstant(obj, 'PI', 3.14);obj.PI = 3.15; // Will not change the valueconsole.log(obj.PI); // 3.14// With enumerable optiondefineConstant(obj, 'E', 2.718, { enumerable: true });console.log(Object.keys(obj)); // ['E'] Copy
const obj = {};defineConstant(obj, 'PI', 3.14);obj.PI = 3.15; // Will not change the valueconsole.log(obj.PI); // 3.14// With enumerable optiondefineConstant(obj, 'E', 2.718, { enumerable: true });console.log(Object.keys(obj)); // ['E']
Defines a non-writable and non-configurable property