4

Can someone tell me what exactly the two above lines of javascript do? And more importantly, what it's called so I can search some javascript references to learn about it? I assume they are both creating some form of an array that objects can be added to...?

Termininja
  • 6,167
  • 12
  • 45
  • 48
Wavel
  • 926
  • 8
  • 30

2 Answers2

8

Curly braces are syntax for creating a Javascript object (which is really a glorified collection of key/value pairs); the brackets make a resizable array.

These are called literals, and they're a handy shortcut to help you make objects and arrays without a lot of typing (good, because you use them all the time). Many other programming languages have similar literal syntax for maps and arrays.

J Cooper
  • 16,702
  • 11
  • 63
  • 107
2

It creates an empty dictionary in map and an empty array in list.

Read up on these structures at http://www.geocities.com/schools_ring/ArrayAndHash.html.

Sophie Alpert
  • 133,880
  • 36
  • 215
  • 235
  • Your link calls javascript objects hash tables, you call them dictionaries. Just call them objects - calling them something else is misleading at best - see http://stackoverflow.com/questions/368280/javascript-hashmap-equivalent#383540 – Christoph Jan 06 '09 at 10:57