Learn JavaScript
❯ objects.property_access

Property Access: Dot, Bracket & Computed in JavaScript

$concept

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.

$how it works
1

Dot for static names

user.name — the default: readable, short, limited to valid identifiers known up front.

2

Brackets for dynamic

user[key], user["first-name"], user[0] — variables, computed strings, and non-identifier keys.

3

Computed keys in literals

{[prefix + i]: value} builds keys at creation — dynamic property names without follow-up assignment.

4

Missing is undefined

user.missing reads undefined silently — convenient drilling, and the source of deep-chain TypeErrors.

$example
let user = { name: "Ada", "fav-color": "blue" };
let key = "name";
console.log(user.name, user[key], user["fav-color"]);
Output
Ada Ada blue
1Dot reads the static name; bracket-with-variable reads the same property dynamically.
2The dashed key is unrepresentable with dots — brackets handle it.
3Three forms, same object — access shaped by what is known when.
$use cases
Dynamic keys from variables and computed strings
Dashed/spaced API field names via brackets
Computed literal keys for generated property names
Guarding deep chains with ?. after understanding bare-undefined behavior

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.