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

Vic Mercier
Vic Mercier
3,276 Points

Is it normal if I don't understand how objects are useful ?(I just did the first lesson of objects litteral )

Same question

5 Answers

Just to piggyback off what Travis Howk explanation.

Object makes it easy to group properties of something together.

var dog = {
  name : 'Spot',
  age : 3,
  breed : 'Beagal',
  speak : function() {
    console.log("Woof Woof")
  }
};

Without using object, then you would have to create variables for different properties.

var dogName = 'Spot';
var dogAge = 3;
var dogBreed = 'Begal';
var dogSpeak = function() {
  console.log("Woof Woof");
}

Although it's doable, as your code gets larger and more complex, it get's harder to track all those things you were storing in the variables, especially if your naming of the variable are not consistent.

Thank you for the comparison. Very helpful

I would say that it's perfectly normal if you don't understand how ANYTHING in a new language is useful. You're at the stage where you're getting your feet wet with certain software elements, so treat them like if you're browsing tools. Just like if you walk into Home Depot and you see all of these carpentry tools and plumbing tools and you kinda/sorta see how you can use them, but you're not really sure exactly how they're useful or what the difference between one or the other is. It takes time and familiarity and exposure with how the tool is actually used by a professional in order for you to "get it".

Objects are really useful for providing organization to things. Take this example. Say you want to tell me about a pet you have.

Without objects, you would have to tell me all of the different things about your pet one at a time and even then, there isn't really a good way to structure all the things you would have to tell me. But if you had an object for a pet, you could use all of the attributes of that object to tell me all about that pet. In addition, you could create methods specifically for the pet object for the sake of ease of use and anytime you called on that object, all of the methods would be right there as well.

Technically, everything in JavaScript is an Object. It is to help you stay organized but also because it is an Object-Oriented Language it will help you to learn it. It can look scary at first but Objects are really similar to a two-dimensional array in a sense. Hope this helps.

Objects are great for searching through things or making sure that data stays connected. Check out my website gamersforecast.com. Here I am using Algoia to search through a list of object and return objects that have similar or matched properties. (Using the Filter)