DEV Community

Cover image for What is an Object in JavaScript? : Part II

What is an Object in JavaScript? : Part II

Tahir Ahmed Tapadhar on July 27, 2020

In this post we will go into a bit deeper understanding of how an object is structured, enumerating properties of an object, property descriptors, ...
Collapse
 
pentacular profile image
pentacular

In javascript an object key can only be a string.

They may also be Symbols.

It is also worth noting that Arrays are objects, and that while numbers are effectively converted to strings, in practice they are not, unless some operation is performed which requires the string value to be exposed.

So it may be better to say that they are referred to by strings and Symbols, rather than actually being those.

Collapse
 
ahmedtahir profile image
Tahir Ahmed Tapadhar

Couldn't have put that in a better way myself. Yes, after the introduction of Symbols in ES6, an object key can be either a string or a Symbol. Also, all keys in the square bracket notation are converted to string unless they're Symbols. Since this post was targeted to an audience who've just started with JS, I was trying not to get into Symbols for now :)

Collapse
 
pentacular profile image
pentacular

Let's consider x[0].

Here 0 probably actually won't be converted to a string, at least until you try to look at it in a way that requires presenting it as a string.

So, I think it's worth distinguishing between "X is Y" and "X is presented as Y in some situations." :)