Created
May 12, 2018 16:07
-
-
Save carlwiedemann/6a2cd2730fd031333e330fd1fb2cd88e 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
// See https://stackoverflow.com/questions/13104494/does-javascript-pass-by-reference | |
(function(){ | |
var foo = [ | |
'hello' | |
]; | |
var replace_the_argument = function (some_array) { | |
some_array = ['hola']; | |
return some_array; | |
}; | |
console.log('result of replace_the_argument():'); | |
console.log(replace_the_argument(foo)); | |
console.log('original:'); | |
console.log(foo); | |
})(); | |
(function(){ | |
var foo = [ | |
'hello' | |
]; | |
var mutate_the_argument = function (some_array) { | |
some_array.push('goodbye'); | |
return some_array; | |
}; | |
console.log('result of mutate_the_argument():'); | |
console.log(mutate_the_argument(foo)); | |
console.log('original:'); | |
console.log(foo); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: