I have seen two terms used with respect to objects in JavaScript, one is it's property and other is it's attribute. What are the differences between these terms?
Each data property (object property that store data) has not only the name-value pair, but also 3 attributes (the three attributes are set to true by default):
- Configurable Attribute: Specifies whether the property can be deleted or changed.
- Enumerable: Specifies whether the property can be returned in a for/in loop.
- Writable: Specifies whether the property can be changed.
Original context: http://javascriptissexy.com/javascript-objects-in-detail/
What is Attribute and What is Property in Javascript?
In General, Both attribute and property are same. Both indicates Quality,in technical terms Key value pairs,So Key is the attribute/property's name and Value is nothing but it's Value.
What is the difference ?
Difference is the context not the meaning.
Why two terms are used ?
Because even a property of an Object may have property , which is termed as attribute.
what are Object's Attributes in Javascript?
Apart from Object's properties, Object has three attributes. They are are prototype, class, and extensible
Ex :
var SampleObject = { Name : "ObjName", id : "0"} // user created
Actual Object's structure :
var SampleObject = {class :someValue, // Attribute
prototype : someValue, // Attribute
extensible : someValue, // Attribute
Name : "ObjName", // Property
id : "0" // Property
}
what are Object's Properties in Javascript?
All the Key value pairs in the object are Object's Properties.
What are the attributes of all the Properties of an Object in JavaScript?
Every Property of an Object has the below 3 attributes. Configurable, Enumerable, and Writable , The values are boolean.
//Ex :
var SampleObject = { key1 :{ p1 : "v1"}} // user created
//Actual Structure :
var SampleObject = { class :someValue, // Attribute
prototype : someValue, // Attribute
extensible : someValue, // Attribute
key1 : { Configurable : true, // attribute
Enumerable : true, // attribute
Writable : true // attribute
p1 : "v1" //property
} // proeperty
}
Attributes are additional elements of the observed object.
Properties are characteristics of the observed object, are part of it.
In javascript these are interchangeable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With