While reading a book of JavaScript I read that
all the attributes of Data Properties defaults to true when “defined directly on an object”.
then after some description it again says that
“When you are using Object.defineProperty()”, the values for configurable, enumerable, and
writable default to false unless otherwise specified.
I guess, in first statement “defined directly on an object” means using dot operator or by object literal notation like this:
var obj = new Object();
obj.name = "Mahesh";
But is there any way to experiment to check what these attributes have been set to, after the property has been added to the object by either method?
You can use
getOwnPropertyDescriptor:descwill contain the the flagsconfigurableandenumerable. If the property is a data descriptor (nogetorset),descwill also containvalueand the flagwritable. If the property is an accessor descriptor,descwill also contain thegetandsetmethods.