// 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
Last active
July 17, 2018 10:12
-
-
Save amysimmons/56b412c4d8d56ddea9e3ba986f75f179 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment