Created
November 16, 2022 19:21
-
-
Save bookcasey/1b0605f3a3d6c18f9f63b7515758f94b to your computer and use it in GitHub Desktop.
This file contains 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
// Mutating data | |
const favoriteNumbers = [1,2,3]; | |
// favoriteNumbers.push(4); // Mutated favoriteNumbers | |
const newFavoriteNumbers = [...favoriteNumbers, 4]; // No mutation here! | |
const removedOne = favoriteNumbers.slice(1, 2); // Mutates the array, no good | |
console.log('removedOne', removedOne) | |
console.log('favoriteNumbers', favoriteNumbers); | |
let a = 10; | |
// a = 20; // Mutate `a` | |
// count++; // Mutated count | |
const b = a + 10; // NOT mutating a | |
// console.log(a); | |
// console.log(b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment