Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


jQuery/Javascript variable arrays, brackets [ ] or braces { }?

Hi! I'm at Andrew's Responsive Slider part for jQuery. At one point of the tutorial he said to create a new variable but he used braces { } instead of brackets [ ].

The code is as follows:

var options =  {navigationControl: 'false', animation: 'slide'};

From the earlier Javascript lessons I had learned to create arrays you need to use brackets [ ]. So what is the difference between braces { } and brackets [ ] in creating arrays? Which should I use during which occasions? Are the ones above called Associative Arrays, does that mean these arrays exist already and are just being referred to using braces { }?

As you can see, I'm pretty much the noobest noob at this lol. Thanks for taking time to answer!

1 Answer

Good question! Being a Rubyist, I was surprised to find that there is no actual Hash / Associative Array class in Javascript. What looks like an hash is acutally an Object. But it works just like a Hash:

var stuff = {'tree': 'plant', 'tiger': 'feline'}
--> "plant"
--> "feline"

Here's some more info: http://www.quirksmode.org/js/associative.html