Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Object Literal

Jeanette Trudell
Jeanette Trudell
11,460 Points

I only have experience with one other programming language (Ruby), but aren't these object literals just hashes?

This is just the first video, so perhaps it gets more complicated, but what he is describing seem to be simple key/value pairs.

5 Answers

It is a little bit odd indeed, personally for me coming from the Python world - these objects are definitely associative arrays. Me too I was expecting to see here the OOP stuff but I think that's covered in later courses. I've poked around the net and I think I've found the answer:

"Objects in JavaScript are kind of two-faced. From one side, an object is an associative array (called hash or dictionary in some languages). It stores key-value pairs. From the other side, objects are used for object-oriented programming, and that’s a different story."

Also If I understand properly, in JavaScript, there are no classes - instead, an object inherits from another object (but I guess that's covered later also).

Objects in JavaScript are hashes, maps, whatever you decide to call them, but... Most of JS entities are Objects. =)

@Jeanette Trudell I'm glad to see someone else coming from ruby, thinking JS objects are simply hashes as well. I had the same thought, and have yet to see otherwise. Maybe in a more advanced course, their differences with emerge?

NO

Jeanette Trudell
Jeanette Trudell
11,460 Points

I suppose if you were coming from JS to Ruby, you might be equally confused by Ruby's hashes!

willyraider
willyraider
6,550 Points

Kenneth Love told us that everything is an object. At least in python :-)

Andrew Stillson
Andrew Stillson
5,577 Points

Kenneth Love is so dreamy... oh, that's not the topic!