JS Object Property Names

JavaScript Objects are denoted by {} and they refer to arbitrary collections of properties.

var aObject = {
blah: 1,
blah2: 2,
“3blah”: 3,
“blah 4”: 4
};

You can refer to an object with dot notation if the property name is a valid variable name. In JavaScript, variables cannot start with a number or have spaces.

In the example above, you could get the values for blah and blah2 with dot notion, but the other examples you would need brackets. Brackets are used to evaluate and expression in this case.

console.log(aObject.blah);
// 1

console.log(aObject.blah2);
// 2

console.log(aObject[“3blah”]);
// 3

console.log(aObject[“blah 4”]);
// 4