Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 2, 2014 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/7d62ddf7939893706876 to your computer and use it in GitHub Desktop.
Save devdays/7d62ddf7939893706876 to your computer and use it in GitHub Desktop.
Object JavaScript - Assign by Reference
function changeStuff(num, obj1, obj2)
{
num = num * 10;
obj1.item = "changed";
obj2 = {item: "changed"};
}
var num = 10;
var obj1 = {item: "unchanged"};
var obj2 = {item: "unchanged"};
changeStuff(num, obj1, obj2);
console.log(num);
console.log(obj1.item);
console.log(obj2.item);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment