Property Access: Dot, Bracket & Computed in JavaScript
Three access forms cover every case: dot (user.name — static, readable, identifier-only), brackets (user["na" + "me"] — dynamic keys, non-identifier names, variables), and computed keys in literals ({[key]: value}). Anything not a valid identifier (spaces, dashes, digits-first) requires brackets.
Missing properties yield undefined (never errors) — the leniency behind both convenient drilling and the dreaded Cannot read properties of undefined two levels down. Optional chaining (?.) now guards chains explicitly.
Dot for static names
user.name — the default: readable, short, limited to valid identifiers known up front.
Brackets for dynamic
user[key], user["first-name"], user[0] — variables, computed strings, and non-identifier keys.
Computed keys in literals
{[prefix + i]: value} builds keys at creation — dynamic property names without follow-up assignment.
Missing is undefined
user.missing reads undefined silently — convenient drilling, and the source of deep-chain TypeErrors.
let user = { name: "Ada", "fav-color": "blue" };let key = "name";console.log(user.name, user[key], user["fav-color"]);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.