Check the specs
PropertyDefinition : PropertyName : AssignmentExpression
- Return PropName of PropertyName.
This part of spec suggests the formal syntax of the property name with its value.
Also, before that this part of the spec suggest that propertyName could be literalPropertyName
which need not be described as a string.
PropertyName[Yield] :
LiteralPropertyName
ComputedPropertyName[?Yield]
LiteralPropertyName :
IdentifierName
StringLiteral
NumericLiteral
This is why you will get same result for both name
and "name"
.
However, if the property name is first name
, then you need to use the string otherwise you will get a compilation error since after the property name a colon :
is expected.
//correct syntax
var ourDog = {
"first name": "Camper"
};
//incorrect syntax
var ourDog = {
first name: "Camper" //since after first there is no colon so there will be compilation error
};