Skip to content

Instantly share code, notes, and snippets.

@gotraveltoworld
Created May 26, 2017 03:51
Show Gist options
  • Save gotraveltoworld/257186eb847762a60b8af9cb9938af4c to your computer and use it in GitHub Desktop.
Save gotraveltoworld/257186eb847762a60b8af9cb9938af4c to your computer and use it in GitHub Desktop.
Is JavaScript a pass-by-reference or pass-by-value language?
function changeStuff(a, b, c)
{
a = a * 10;
b.item = "changed";
c = {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