Skip to content

Instantly share code, notes, and snippets.

@darleykrefta
Created March 20, 2021 13:11
Show Gist options
  • Save darleykrefta/4805ff2b53e344ef871c7a2deb8041f3 to your computer and use it in GitHub Desktop.
Save darleykrefta/4805ff2b53e344ef871c7a2deb8041f3 to your computer and use it in GitHub Desktop.
const droids = ['R2-D2', 'C-3PO', 'K-2SO']

// define newDroids with droids reference
const newDroids = droids

// add 'BB-8' value to start of the new array created
newDroids.unshift('BB-8')

// the original variable is updated too, because it is the original reference
console.log(droids)
// ['BB-8', 'R2-D2', 'C-3PO', 'K-2SO']

// variable newDroids was updated by the reference
console.log(newDroids)
// ['BB-8', 'R2-D2', 'C-3PO', 'K-2SO']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment