Skip to content

Instantly share code, notes, and snippets.

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

// put new value in first element, define newDroids with a spread of droids, creating a new reference
const newDroids = ['BB-8', ...droids]

// the original variable wasn't updated
console.log(droids)
// ['R2-D2', 'C-3PO', 'K-2SO']

// only the new one was updated
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