JavaScript theorytheory 0/50 · 0%
Objects · medium

21. Objects and property access

Dot vs bracket, shorthand and computed keys.

Objects map string (or symbol) keys to values. Bracket access allows dynamic keys; shorthand and computed keys keep construction terse.

const key = "chainId";
const net = { name: "Base", [key]: 8453 };
console.log(net[key]); // 8453

Property order is insertion order for string keys, except integer-like keys, which come first in ascending order.

Check your understanding

  1. 1. When must you use bracket access?

  2. 2. What are object keys coerced to?

  3. 3. What does `{ [k]: v }` do?