Read-only property

suggest change

Using 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents