Sample Function which is accepting object as parameter and modifying the object property in two different ways. First by using . (dot) notation which is reflected outside function call and second with creating new hash.
function myFunc(theObject)
{
theObject.make = "Toyota";
theObject = {make: "Ford", model: "Focus", year: 2006};
console.log(theObject.make); // logs "Ford"
}
var mycar = {make: "Honda", model: "Accord", year: 1998};
console.log(mycar.make); // logs "Honda"
myFunc(mycar); // Call function to change the 'make'
console.log(mycar.make); // logs "Toyota"
- What is the difference in theObject.make = "Toyota" and theObject = {make:'Ford'}
- Why "Toyota" is visible outside function and not "Ford"