Created
February 15, 2023 02:46
-
-
Save yogeshvar/34c0c717afea2248d9020f82d4ad2cf5 to your computer and use it in GitHub Desktop.
JS Pass-by-Reference
This file contains hidden or 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
// Now pass-by-reference | |
let c = { language: "Javascript" } | |
let d = c | |
console.log(c) // => {language: "Javascript"} | |
console.log(d) // => {language: "Javascript"} | |
// Let's mutate our object 'd' | |
d.language = "Ruby" | |
console.log(c) // => {language: "Ruby"} | |
console.log(d) // => {language: "Ruby"} | |
// Meaning mutating the object d also mutates the object c - Because 'd' points to the same reference-location as 'c' . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment