Objects group named properties—records, config, DOM nodes, and API payloads are all objects.
Syntax
- Literal:
{ id: 1, name: 'Ada' } - Access:
user.nameoruser['name'] - Optional chaining:
user?.profile?.city
Spread
{ ...defaults, ...overrides } shallow-merges objects—common for props and config.
Important interview questions and answers
- Q: Shallow merge?
A: Spread copies top-level keys; nested objects still shared. - Q: Optional chaining?
A: Short-circuits to undefined if intermediate is null/undefined.
Self-check
- Dot vs bracket access?
- When use optional chaining?
Tip: Re-run the playground code for objects-basics and tweak one line before the MCQs.
Interview prep
- Optional chaining?
Safe access when intermediate may be null.