Skip to content

Instantly share code, notes, and snippets.

@darleykrefta
Created March 20, 2021 13:09
Show Gist options
  • Save darleykrefta/b101372371d4f7dd95a21c8d5716d204 to your computer and use it in GitHub Desktop.
Save darleykrefta/b101372371d4f7dd95a21c8d5716d204 to your computer and use it in GitHub Desktop.
const ships = ['X-wing', 'TIE Fighter', 'Millenium Falcon']

// define newShips with a spread of ships, creating a new reference
const newShips = [...ships, 'Destroyer']

// the original variable wasn't updated
console.log(ships)
// ['X-wing', 'TIE Fighter', 'Millenium Falcon']

// only the new one was updated
console.log(newShips)
// ['X-wing', 'TIE Fighter', 'Millenium Falcon', 'Destroyer']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment