Read-only property
suggest changeUsing property descriptors we can make a property read-only. In non-strict code, assignment fails silently and the value stays unchanged. In strict mode, including modules and classes, that assignment throws TypeError.
The writable property in a property descriptor indicates whether that property can be changed or not.
const a = { };
Object.defineProperty(a, 'foo', { value: 'original', writable: false });
a.foo = 'new';
console.log(a.foo);
Console output
original
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents