Created
September 29, 2015 06:23
-
-
Save dd1994/bcdaea3e5d30444e7873 to your computer and use it in GitHub Desktop.
pass by value or pass by reference?
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
'use strict' | |
let func = (a, b, c) => { | |
a = "a-new-value" | |
b = b + "+ b-new-value" | |
c[0] = "c-new-value1" | |
} | |
let a = "a-old-value" | |
let b = "b-old-value" | |
let c = ["c-old-value1", "c-old-value2"] | |
func(a, b, c) | |
console.log(a, b, c) // a-old-value b-old-value [ 'c-new-value1', 'c-old-value2' ] |
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
def func(a, b, c): | |
a = "a-new-value" | |
b = b + "+ b-new-value" | |
c[0] = "c-new-value1" | |
a = "a-old-value" | |
b = "b-old-value" | |
c = ["c-old-value1", "c-old-value2"] | |
func(a, b, c) | |
print(a, b, c) # a-old-value b-old-value ['c-new-value1', 'c-old-value2'] |
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
def func(a, b, c) | |
a = "a-new-value" | |
b = b + "+ b-new-value" | |
c[0] = "c-new-value1" | |
end | |
a = "a-old-value" | |
b = "b-old-value" | |
c = ["c-old-value1", "c-old-value2"] | |
func(a, b, c) | |
puts(a, b, c) # a-old-value | |
# b-old-value | |
# c-new-value1 | |
# c-old-value2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment