const obj = {name: 'Codedrops'};
console.log(obj.name); // Codedrops
/* Set the 'writable' descriptor to false for the 'name' key */
Object.defineProperty(obj, 'name', {
writable: false
});
obj.name = 'ABC';
console.log(obj.name); // Codedrops
Thanks for reading π
Follow @codedrops.tech for daily posts.
Instagram β Twitter β Facebook
Micro-Learning β Web Development β Javascript β MERN stack β Javascript
codedrops.tech
Top comments (2)
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
Yes, but there is a small difference between all of them. Have a post coming up..