Skip to content

Instantly share code, notes, and snippets.

@nola
Last active December 30, 2015 20:39
Show Gist options
  • Select an option

  • Save nola/7882227 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7882227 to your computer and use it in GitHub Desktop.
Passing objects to functions.If you pass an object (i.e. a non-primitive value, such as Array or a user-defined object) as a parameter, and the function changes the object's properties, that change is visible outside the function, as shown in the following example:
var myFunc;
var num = 0;
if (num === 0){
myFunc = function(theObject) {
theObject.make = "Toyota";
theObject.year = "2003";
return theObject;
};
}
var mycar = {make:"Honda", year:"1993"};
console.log(mycar);
myFunc(mycar);
console.log(mycar);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment