const id = "b":
const obj = { [id]: 1};
equals:
const id = "b";
const obj = {};
obj[id] = 1;
As always, the syntax can be found In the Ecma Spec, inside of the Expressions > Primary Expressions > Object Initializer part:
Objects are written like this:
{[id]:2}
ObjectLiteral:
{}
{PropertyDefinitionList}
The property definition list is just some comma seperated Property Definitions:
[id]:2
PropertyDefinitionList:
PropertyDefinition
PropertyDefinitionList,PropertyDefinition
A propertyDefinition might be one of the following:
PropertyDefinition:
IdentifierReference
CoverInitializedName
PropertyName:AssignmentExpression
MethodDefinition
And ours is a PropertyName:AssignmentExpression
, so
[id]
is a PropertyName
, which is a ComputedPropertyName
.
So the next time, justlook it ip in the docs ;)