Skip to content

Instantly share code, notes, and snippets.

@darleykrefta
Created March 20, 2021 12:59
Show Gist options
  • Save darleykrefta/ec45efe6ecbc6a21af7f5571f3abe07f to your computer and use it in GitHub Desktop.
Save darleykrefta/ec45efe6ecbc6a21af7f5571f3abe07f to your computer and use it in GitHub Desktop.
const droid = {
  name: 'R2-D2',
  quality: 'resourceful'
}

// define newDroid with droid reference
const newDroid = droid

// update some attribute
newDroid.quality = 'smart'

// variable droid was affected by that change because it is a reference
console.log(droid)
// [object Object] {
//   name: 'R2-D2',
//   quality: 'smart'
// }

// variable newDroid was updated by the reference
console.log(newDroid)
// [object Object] {
//   name: 'R2-D2',
//   quality: 'smart'
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment