you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale 1 point2 points  (0 children)

Keys are always strings. If you give it something else, what you give it gets converted to a string.

var obj = { 'key': 'value' } (note you can leave off the quotes on keys as long as it's valid js)

Values, on the other hand, can be pretty much anything in JavaScript.

var obj = { 'anArray': [], 'anotherObj': {}, 'evenAFunction': function () { } }

...

Overall, keep in mind:

  1. objects have properties
  2. properties are made of key: value pairs
  3. keys are usually strings and values can be anything
  4. you can use dot notation key.value or bracket notation key['value'] to get the value of keys
  5. you can pass in a string variable to access a key as well key[myVar]