I am learning about the different types of properties an object can have in javascript (own properties, inherited properties, and prototype properties?)
I came across these two articles and I got kind of confused.
Are these two articles referring to the same thing?
When people say inherited properties do they mean prototype properties? Are these terms interchangeable?
How many different types of properties are there?
Thank you in advance! :)
Link to articles:
https://attacomsian.com/blog/javascript-own-inherited-properties
Yes, they're referring to the same thing.
In JavaScript, generally, if you can retrieve a value from an object by referencing a member - eg obj.someProp - then that member (someProp here) is either
A given member reference is either one or the other (or it doesn't exist either on the instance or on any of the prototype objects, in which case it evaluates to undefined).
When people say inherited properties do they mean prototype properties? Are these terms interchangeable?
Mostly. It would be a bit more accurate to say that objects inherit from other objects ("prototypal inheritance"), and that referencing a property on a child object will evaluate to the property on the first parent object that has that property, if the child object does not have it. This section of the spec goes into more detail.
How many different types of properties are there?
Yes, properties can have different types - there are data properties and accessor properties, and properties may also be enumerable (or not), and/or configurable (or not) - but it would be misleading to say that these types are in the same category. The types I've just mentioned are property attributes, and every property directly on an object has some configuration of the above. Prototypal inheritance of properties is a different category - property attributes don't have any notion of inherited properties, because property attributes only refer to properties on an object itself.