Skip to content

Instantly share code, notes, and snippets.

@awilson28
Created March 16, 2017 20:00
Show Gist options
  • Save awilson28/5556a2511878883c68296c84b8a7f502 to your computer and use it in GitHub Desktop.
Save awilson28/5556a2511878883c68296c84b8a7f502 to your computer and use it in GitHub Desktop.
var a = [1, 2, 3];
function doSomething(b){ // the parameter `b` that corresponds to the argument `a` is a copy of a reference to the array a
b = [2]; //if we change b via reassignment inside a function or outside of the function, that reassignment does not affect a
console.log(b) // [2]
}
doSomething(a);
console.log(a) // [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment