Ever wondered how objects in JavaScript use features they never created? 🤔 From where do the methods and properties of objects actually come? They come from something called Prototype ✨ Think of it like this: You don’t own a pen 🖊️ But your friend does. When you need it, you borrow it 🤝 JavaScript works the same way. If an object doesn’t have something, it borrows it from its prototype. 🧱 Object Example const person = { name: "Bushra" }; console.log(person.hasOwnProperty("name")); // true We never wrote hasOwnProperty. So where did it come from? It comes from Object.prototype. JavaScript searches like this: person → Object.prototype → null 📦 Array Example const numbers = [1, 2, 3]; numbers.push(4); numbers.pop(); We never created push or pop. They come from Array.prototype. JavaScript searches like this: numbers → Array.prototype → Object.prototype → null #JavaScript #LearnJS #WebDevelopment #Frontend #CodingJourney #Programming #TechLearning #DeveloperLife #100DaysOfCode #JSBasics
This is how javascript object works behind the scene. Whenever a javascript object or array is created, its class is instantiated which consists of prototype property. There is a chain of prototypes which we can access until it reaches to null. Thank you for bringing this one of the important concept of javascript. BUSHRA NIKHAT
Great BUSHRA NIKHAT thanks for sharing