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

please explain the difference in the out comes of this array versus hash? var a=['hi','buddy']; var b ={hi: 'buddy'};

In my studies in javascript thus far, which have been limited. Ive heard learned a bit about arrays, but I haven't come across any explanation of a hash yet. This is a question Im being asked so I'm just curious if anyone could explain it to me. And maybe post what the outcome would look like and why. thanks anyone

Thanks Chino it does help

1 Answer

Arrays are bound to only storing data types. example

var car = ["Fiat", 500, "850kg", "white"];

//accessing information

console.log(car[0]); // Fiat
console.log(car[1]); // 500
console.log(car[2]); // 850kg
console.log(car[3]); // white

as you can see, there's not much information as to knowing exactly what the data means but with object literals you can organize your data and easily access that information using dot notation. example

var car = {
  make: "Fiat",
  model: 500,
  weight: "850kg",
  color: "white"
};

//accessing information

console.log(car.make); // Fiat
console.log(car.model); // 500
console.log(car.weight); // 850kg
console.log(car.color); // white

In addition to using object literals is that you can also create and call functions as well.

I hope this helps.