Fresh object literals vs variable assignment behavior
📖 Scenario: Imagine you are managing a simple inventory system where you track items and their quantities. You want to understand how creating new objects directly differs from assigning existing objects to new variables.
🎯 Goal: You will create an object representing an item, then assign it to another variable. You will also create a fresh object literal with the same properties. Finally, you will compare how changing one affects the other.
📋 What You'll Learn
Create an object literal called
item1 with properties name set to 'apple' and quantity set to 10.Create a variable called
item2 and assign it the value of item1.Create a fresh object literal called
item3 with the same properties as item1.Change the
quantity of item2 to 20.Print the
quantity of item1 and item3 to observe the difference.💡 Why This Matters
🌍 Real World
Understanding object references is important when managing data in apps, like updating user profiles or inventory items without accidentally changing other data.
💼 Career
Many programming jobs require careful handling of objects and data structures to avoid bugs caused by unintended shared references.
Progress0 / 4 steps