Created
March 16, 2017 20:05
-
-
Save awilson28/7b2a9184cb31eee584a66065cee01220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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