Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created November 10, 2018 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fay-jai/5ccaaae475d7c29a44f2dc8132d52c36 to your computer and use it in GitHub Desktop.
Save fay-jai/5ccaaae475d7c29a44f2dc8132d52c36 to your computer and use it in GitHub Desktop.
function doSomethingWith(array) {
// do something with array here
}
let array = [1, 2, 3]; // In languages like JavaScript, arrays are mutable data structures where you can add and remove values without changing the reference to the underlying object.
doSomethingWith(array); // When doSomethingWith is passed the array as an argument, we pass it by reference. The implication here is that whatever happens inside of the function can mutate the underlying array.
console.log(array); // At this point, you don't actually know what to expect when you log the array - does it still have [1, 2, 3] or does it have other values?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment