Why is javascript object so confusing from the start

Why is javascript objects so confusing? coming from a traditional object oriented style what is a good metal model model that i need to take to consume and understand javascript objects

1 Like

I don’t do a lot of object stuff in other languages, but in javascript I just think of them as a load of key:value pairs.

const myObject = {size: ‘large’, stock: 43};

So you just read or write the values with the keys, like myObject.size would be the string ‘large’.

Gets more complicated when the value can be another object, or a function, but it’s all the same basics.


If you come from Python, you can think about them as similar to dictionaries, Ruby as hashes, or PHP as unordered arrays

1 Like

Considering your username has Java in it, I’ll assume that Java is the one you have experience in. It’s basically an amorphous HashMap<String, Object>. It holds key (String) value (Object) pairs.

In JS, functions are also objects, which means a JS object can also contain functions as its values, though the notation gets annoying at that point.

You can also have multiple layers of nested objects, which is again, essentially a HashMap<String, <String, Objext>>.

I have the same problem, so I don’t know how to help you. The only thing I can tell you is that we are in the same boat.
In fact, after weeks of trying, after months of wasting my head, I finally gave up on JS. I’ll be back, it’s a personal challenge.
I changed course slightly, I’m dealing with something else (other languages, other subjects). Try it too! The important thing is not to be demoralized.
Maybe you just have to wait for the right moment.

What really helped me was watching this youtube video! He explains it in a very logical way :grin:
I hope it helps you!

Youtube video on classes and objects part 1 (has 2 parts I believe)

1 Like

Thank you very much, thankfully the community exists!