Object Literals in JavaScript
Object literals ({name: "Ada", age: 36}) bundle named values into the language's core data structure — records, configs, options, JSON, and (with methods) the basis of OOP. Keys are strings (or Symbols); values are anything, including nested objects, arrays, and functions.
Literals compose: nesting models hierarchies, trailing commas are legal (and diff-friendly), and the same syntax expresses both data (JSON-compatible subset) and behavior (methods). Nearly every API boundary in JavaScript speaks object literals.
Keys and values
{name: "Ada", age: 36} — string keys (quoted or bare identifiers) mapping to any values.
Nesting models depth
{user: {address: {city: "X"}}} — hierarchies as plain data, traversable with chained access.
Trailing commas welcome
{a: 1, b: 2,} is valid — cleaner diffs when fields come and go.
Data plus behavior
Methods inside literals ({x, move() {...}}) turn records into objects with capabilities.
let user = { name: "Ada", age: 36, active: true };console.log(user.name, Object.keys(user).length);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.