liveBook · Manning

Object literal

An object literal is a language expression that directly specifies an object value and its constituent properties or values.

How 2 Manning books explain it

Essential TypeScript 5, Third Edition

Object literal syntax is JavaScript syntax for directly defining an object by listing its properties and values.

How it is used
Uses object literals to define everyday JavaScript data and return typed records from application methods.
How deep it goes
Explains brace syntax, property access, shape inference, aliases, and heterogeneous-array errors without descending into object internals.
Examples
Demonstrates hat and boots products, a mixed product array, and a typed todo-item count record.
What you can do after
Build object literals, use their properties, name their shapes, and diagnose unsafe property access in mixed arrays.

Read how Essential TypeScript 5, Third Edition explains object literal →

The Joy of JavaScript

A JavaScript syntax form for creating an object directly from a literal expression.

How it is used
Groups related data for one-time use or supplies a simple object that can be passed to or returned from a function.
How deep it goes
Defines direct creation and contrasts alternatives, then shows a literal serving as a prototype without developing property descriptors.
Examples
Uses a transaction literal containing sender and recipient data, then links a money transaction to it with Object.create.
What you can do after
Apply it to create compact one-off data objects and prototype objects, while selecting factories or classes for repeated shapes.

Read how The Joy of JavaScript explains object literal →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.