If you don’t know how to create a object in javascript or various ways to create a object in JS. Please follow below link

<a href=”https://medium.com/@ghatudb/different-ways-of-creating-objects-in-javascript-a587dc6daa7f”> Different Ways To Create Object </a>

Once you know how to create an object in javascript, you may wish to learn about object property descriptors.

var myObj = { name: ‘Shailender’ , age: ‘30’ }

Object has more info rather than just value console.log(Object.getOwnPropertyDescriptor(myObj,’name’));

Now you can see if writable is true then you can re-write the property


Writable: false

As of now, you know object property descriptors, so if you are required to make a property Read-Only, you will set the property writable to false.


With Default behaviorof Object, you can add properties to an object. Thus, the below operation is possible:

myObj.hobby = ‘ Football’;

To prevent the default behavior from adding properties dynamically in an object, you need to use Object.preventExtensions(). This method prevents an object from having new properties added to it.


After using Object.preventExtensions on the object, if you add new property color, JavaScript will ignore it.

I’m a Javascript Developer and Architect specializing in Web technologies. Love to contribute in Open Source, AI and Machine Learning.