Understanding Object.create() in JavaScript: A Coding Task

📝 JavaScript Interview Coding Task Question – Day 72 Look at this code snippet 👇 ✅ Answer & Explanation: 1️⃣ Object.create(proto) creates a new object whose prototype is proto. It does not call a constructor function. 2️⃣ So child.name → "Kiran" because JavaScript looks up the prototype chain (since child doesn’t have its own name). 3️⃣ After setting child.name = "Sai", the name property is now created on child itself — it shadows the prototype’s property. 4️⃣ proto.name remains "Kiran", proving that child and proto are independent objects connected by prototype inheritance. ✨ Tip: 👉 Object.create() is great for lightweight inheritance without constructors. 👉 Property lookups follow the prototype chain, but assignments always go to the current object unless explicitly modified on the prototype. #100DaysOfCode #JavaScript #Frontend #WebDevelopment #CodingInterview #JSChallenges #LearnInPublic #DailyCoding #kirantechnophile

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories