Skip to content

Instantly share code, notes, and snippets.

@yogeshvar
Created February 15, 2023 02:46
Show Gist options
  • Save yogeshvar/34c0c717afea2248d9020f82d4ad2cf5 to your computer and use it in GitHub Desktop.
Save yogeshvar/34c0c717afea2248d9020f82d4ad2cf5 to your computer and use it in GitHub Desktop.
JS Pass-by-Reference
// 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