Skip to content

Instantly share code, notes, and snippets.

@amysimmons
Last active July 17, 2018 10:12
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 amysimmons/56b412c4d8d56ddea9e3ba986f75f179 to your computer and use it in GitHub Desktop.
Save amysimmons/56b412c4d8d56ddea9e3ba986f75f179 to your computer and use it in GitHub Desktop.
// REGULAR OBJECTS (cannot have non-string keys)

// create empty object x 
x = {}

// create object y 
y = {id: 1}

// attempt to put y into x as the key with a value of 'amy'
x[y] = 'amy'

// log x and see that y got stringified to "obejct Object" 
x // {[object Object]: "amy"}

// create object z 
z = {id: 2}

// attempt to put z into x as the key with a value of 'swift'
x[z] = 'swift'

// log x and see that z was also stringified to "object Object"
// this meant the already existing "object Object" key was accessed 
// and its value set to 'swift'
x // {[object Object]: "swift"}

// MAPS (can have non-string keys)

x = new Map()

y = {id: 1}
x.set(y, 'amy')
x.size // 1

z = {id: 2} 
x.set(z, 'swift')
x.size // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment