Skip to content

Instantly share code, notes, and snippets.

@awilson28
Created March 16, 2017 20:05
Show Gist options
  • Save awilson28/7b2a9184cb31eee584a66065cee01220 to your computer and use it in GitHub Desktop.
Save awilson28/7b2a9184cb31eee584a66065cee01220 to your computer and use it in GitHub Desktop.
var a = [1, 2, 3];
var c = a;
function doSomething(b){
// b is a copy of a reference to the array a
b.push(4);
console.log(b) // [1, 2, 3, 4]
}
doSomething(a);
console.log(a) // [1, 2, 3, 4]
// mutate a direct reference to a
c.push(5);
console.log(c) // [1, 2, 3, 4, 5]
console.log(a) // [1, 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment