Member-only story
JavaScript: Property accesses
How property access is performed under the hood
Note: This post is somewhat advanced and assumes you have some understanding of what [[Prototype]] is and how it works.
If you’ve worked with JavaScript you’ve most likely come across objects and property access. Here’s what it looks like
// object literal
const obj = {
x: 52
};// property access
obj.x;
The obj.x is called the property access. This bit of code actually performs a [[Get]] operation on obj . Lets take a look at how it works
[[Get]]
The built in operation first looks to see if the object in question has the property or not. If the property is found on the object, the value is returned. So, if we consider the example above it’ll return 52.
console.log(obj.x); //52Pretty simple and straight forward. However, if the property is not found in the object, the [[Get]] algorithm traverses the [[Prototype]] chain to see if it can find the property there. If it, by any means, doesn’t find a value for the property being requested it returns the value undefined .
Note: Discussion on the [[Prototype]] chain is long and I would be doing it injustice if I tried to cram it in…











