const key = "prop_" + "computed";
const obj = {
[key]: 42, ["other"]: 100, simple: 1 };
{
function assert(condition, message) {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}
}
assert(obj.prop_computed === 42, "obj.prop_computed should be 42");
assert(obj["other"] === 100, "obj['other'] should be 100");
assert(obj.simple === 1, "obj.simple should be 1");
const obj2 = {
["prop_" + (() => 42)()]: 42,
};
assert(obj2["prop_42"] === 42, "obj2['prop_42'] should be 42");
assert(obj2.prop_42 === 42, "obj2.prop_42 should be 42");
true;