Skip to content

Instantly share code, notes, and snippets.

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

// define newShips with ships reference
const newShips = ships

// push 'Destroyer' value to new array created
newShips.push('Destroyer')

// the original variable is updated too, because it is the original reference
console.log(ships)
// ['X-wing', 'TIE Fighter', 'Millenium Falcon', 'Destroyer']

// variable newShips was updated by the reference
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