Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created April 18, 2018 09:24
Show Gist options
  • Save gladchinda/4103b43ae04e1292774802161b1a5ac0 to your computer and use it in GitHub Desktop.
Save gladchinda/4103b43ae04e1292774802161b1a5ac0 to your computer and use it in GitHub Desktop.
const rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
const rainbowClone = rainbow;
// Both rainbow and rainbowClone point to the same
// array reference in memory, hence it logs (true)
console.log(rainbow === rainbowClone); // true
// Keep only the first 3 items and discard the rest
rainbowClone.splice(3);
// The change on rainbowClone also affected rainbow
console.log(rainbow); // ['red', 'orange', 'yellow']
console.log(rainbowClone); // ['red', 'orange', 'yellow']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment