ππ§πππ«π¬πππ§ππ’π§π π©π«π¨ππ¨ππ²π©ππ₯ π’π§π‘ππ«π’πππ§ππ

hey there π i'm Samia, a Backend developer turning to frontend world. i used to work as a Laravel and PHP developer for 3 and half years, in that journey, i had to deal from time to time with some frontend tasks, like fixing responsiveness or converting some psd files into HTML & CSS, that was when i fall in love with it.
I loved the idea of turning creative and beautiful design into reality, so i made that career switch and now turning fully to Frontend development.
Feel free to checkout my journey on Instagram or just pass Hi
as developers we deal with objects most of the time, but have you ever wondered how JavaScript objects can access a treasure trove of built-in methods, seemingly by magic? Let's demystify it!
Take this as an example: πππππ ππππ = { ππππ: "π±πππ" };
π€ It appears as though the object has access to various methods even though we didn't explicitly create them, for example, we can access ππππ.ππππΆπππ·πππππππ(ππππ), even though we did not create it in user, it still works!
How is that possible? The key lies in understanding π©π«π¨ππ¨ππ²π©ππ₯ π’π§π‘ππ«π’πππ§ππ.
π οΈ The truth is, when we create an object, JavaScript sets up a prototype chain for that object. Each object gets a hidden [[ππ«π¨ππ¨ππ²π©π]] property, This property holds a reference to its parent object. If it's a nested object, it references its immediate parent. If it's a top-level object like user, it references the πππ£πππ object.
π when is the prototype useful? When you access a property or method on an object, and that property or method doesn't exist on the object itself, JavaScript will look for it in the object referenced by its [[ππ«π¨ππ¨ππ²π©π]] property.
in the attached example, you notice that we have a πππππ object, that inherits from a ππππ object
When you call πππππ.πππππ(), JavaScript looks for the greet method on the πππππ object. Since it doesn't find the method there, it proceeds to check the prototype, which is the ππππ object.
JavaScript finds the greet method on the ππππ object, and it executes that method, producing the output: "Hello, my name is Sammy.".
For more details check out: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes



