Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created January 13, 2020 17:07
Show Gist options
  • Select an option

  • Save r3dm1ke/bcb65f699c977ca539da0bfdb2e5f7b8 to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/bcb65f699c977ca539da0bfdb2e5f7b8 to your computer and use it in GitHub Desktop.
Primitive vs complex data structures
// string is a primitive data type
const name = 'Michael';
name.toUpperCase();
// toUpperCase is not a method; it does not mutate
// the original variable
console.log(name); // Michael
// instead, it returns a new one
const NAME = name.toUpperCase();
console.log(NAME); // MICHAEL
// list is a complex data type
const names = ['Alice'];
// push mutates the original array
names.push('Bob');
console.log(names); // ['Alice', 'Bob']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment