HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Object is a data type that stores information in the form of key-value pairs. Each element is mapped to its own key and the order of the elements is completely unimportant.</p>
1 <p>Object is a data type that stores information in the form of key-value pairs. Each element is mapped to its own key and the order of the elements is completely unimportant.</p>
2 var cat = { name: 'Muffin', age: 5 }; console.log(cat.name); // Logs 'Muffin' in the console console.log(cat.age); // Logs 5 in the console console.log(cat.color); // Logs undefined, there is no such key in the object cat.age++; // Increases cat’s age by 1 console.log(cat.age) // Logs 6 in the console cat.name = 'Rocky'; // Replaced name property value on the outside console.log(cat.name); // Logs 'Rocky' in the console<h3>Transfer by reference</h3>
2 var cat = { name: 'Muffin', age: 5 }; console.log(cat.name); // Logs 'Muffin' in the console console.log(cat.age); // Logs 5 in the console console.log(cat.color); // Logs undefined, there is no such key in the object cat.age++; // Increases cat’s age by 1 console.log(cat.age) // Logs 6 in the console cat.name = 'Rocky'; // Replaced name property value on the outside console.log(cat.name); // Logs 'Rocky' in the console<h3>Transfer by reference</h3>
3 <p>There is always one object here, no new place is created in memory for a copy of the object. Each variable contains a reference to a single object, not a new separate entity. Therefore, when we change something in an object through one of the variables that contains a reference to it, the changes are visible in all other variables, be it twenty or forty of them. This is an important feature of objects to remember. It’s called<em>transferring objects by reference</em>.</p>
3 <p>There is always one object here, no new place is created in memory for a copy of the object. Each variable contains a reference to a single object, not a new separate entity. Therefore, when we change something in an object through one of the variables that contains a reference to it, the changes are visible in all other variables, be it twenty or forty of them. This is an important feature of objects to remember. It’s called<em>transferring objects by reference</em>.</p>
4 var firstCat = { name: 'Muffin', age: 5 }; var secondCat = firstCat; console.log(secondCat); // Logs {"name":"Muffin","age":5} firstCat.name = 'Snowball'; console.log(secondCat); // Logs {"name":"Snowball","age":5}<a>Continue</a>
4 var firstCat = { name: 'Muffin', age: 5 }; var secondCat = firstCat; console.log(secondCat); // Logs {"name":"Muffin","age":5} firstCat.name = 'Snowball'; console.log(secondCat); // Logs {"name":"Snowball","age":5}<a>Continue</a>