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
// mutable | |
const bands = ["Metallica", "Queen"]; | |
bands.push("Nirvana"); | |
// immutable | |
const someBands = ["Metallica", "Queen"]; | |
const bands = [...someBands, "Nirvana"]; |
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
// impure (using side effect instead of return value) | |
function addTaco(array) { | |
array.push("taco"); | |
} | |
// impure (using shared variable instead of argument) | |
function addTaco() { | |
return [...globalArray, "taco"]; | |
} |
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 names = ["Han", "Chewbacca", "Luke", "Leia"]; | |
// imperative | |
const shortNames = []; | |
for (let i = 0; i < names.length; i++) { | |
if (names[i].length < 5) { | |
shortNames.push(names[i]); | |
} | |
} |