In JavaScript, if you type
typeof("2")
you should get string
.
And if you type
typeof(2)
you should get number
.
Now my question is, it is said that when you define an object, the key must be a string.
so this is legal
apple = {"color":"red"}
However, if I change the key to a number wrapped in the inverted commas, it should work as anything inside of inverted commas
apple={"2": "red"}
But If I call the object property, apple.2
, this will fail with error Unexpected number
.
so am just curious, what am I missing here while defining the objects in JavaScript.