Created
April 18, 2018 09:24
-
-
Save gladchinda/4103b43ae04e1292774802161b1a5ac0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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