DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at


Prevent an object's properties value from updating

const obj = {name: 'Codedrops'};
console.log(; // Codedrops

/* Set the 'writable' descriptor to false for the 'name' key  */
Object.defineProperty(obj, 'name', {
        writable: false
}); = 'ABC';
console.log(; // Codedrops
Enter fullscreen mode Exit fullscreen mode

Thanks for reading πŸ’™

Follow for daily posts.

Instagram ● Twitter ● Facebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

Top comments (2)

lowlighter profile image
lowlighter πŸ¦‘

One may look also at Object.seal and Object.freeze, to respectively prevent an object from being extended with new properties or to be modified in any way

ml318097 profile image
Mehul Lakhanpal

Yes, but there is a small difference between all of them. Have a post coming up..