Learn JavaScript
❯ objects.shorthand

Shorthand & Computed Properties in JavaScript

$concept

Shorthand compresses literals: {name, age} means {name: name, age: age} when variables share field names, methods drop the function keyword ({go() {...}}), and computed keys ({[key]: value}) build dynamic names inline. Together they shrink object construction to its essence.

These aren't sugar-only β€” shorthand dominates modern code (React props, config builders, return bundles), computed keys enable generated property names, and method shorthand defines proper methods (with dynamic this, unlike arrows).

$how it works
1

Variable shorthand

{name, age} pairs same-named variables as fields β€” the return-bundle and props idiom.

2

Method shorthand

{go() {...}} defines real methods (dynamic this) β€” shorter than go: function() and correct unlike arrows.

3

Computed keys

{[prefix + i]: value} evaluates key expressions at creation β€” dynamic names without follow-up assignment.

4

Combine freely

{name, [k]: v, go() {}} mixes all three β€” dense but complete construction in one literal.

$example
let name = "Ada";
let n = 1;
let user = { name, [`id_${n}`]: 7 };
console.log(user.name, user.id_1);
Output
Ada 7
1name shorthand binds the variable as the name field.
2The computed key evaluates to id_1, storing 7 under the generated name.
3Both read back normally β€” construction compressed, access unchanged.
$use cases
Return bundles ({data, error}) and props objects
Method definitions with correct dynamic this
Generated keys (id_, field_) computed inline
Config builders mixing static and dynamic fields

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself β€” building beats watching.