Shorthand & Computed Properties in JavaScript
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).
Variable shorthand
{name, age} pairs same-named variables as fields β the return-bundle and props idiom.
Method shorthand
{go() {...}} defines real methods (dynamic this) β shorter than go: function() and correct unlike arrows.
Computed keys
{[prefix + i]: value} evaluates key expressions at creation β dynamic names without follow-up assignment.
Combine freely
{name, [k]: v, go() {}} mixes all three β dense but complete construction in one literal.
let name = "Ada";let n = 1;let user = { name, [`id_${n}`]: 7 };console.log(user.name, user.id_1);Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself β building beats watching.