Objects Basics
EasyIn plain terms
An object is a collection of key-value pairs. Each key is a name (like "age" or "name"), and each value can be anything—a number, string, array, or even another object. Objects let you group related data together.
You can add new properties, change existing ones, or delete them. Use dot notation (user.name) when the key is a valid identifier, or bracket notation (user["full name"]) for keys with spaces or special characters. Objects are stored by reference, so assigning an object to a variable does not copy it—both variables point to the same object.
What you need to know
- •Key-value pairs
- •Dot and bracket access
- •Reference type - shared by reference
Try it yourself
Copy the code below and run it in your browser console or a code editor:
const user = {
name: 'Alice',
age: 25,
'full name': 'Alice Smith' // bracket notation for spaces
};
user.name; // "Alice"
user['full name']; // "Alice Smith"
user.email = 'a@b.com'; // add
user.age = 26; // update
delete user.email; // delete
// Shorthand
const name = 'Bob';
const person = { name }; // { name: 'Bob' }Why this matters
Objects are everywhere in JS—APIs, config, React state. Interviewers ask about reference vs value, shallow vs deep copy, and object destructuring.
How it connects
Objects underpin classes (instances are objects). JSON.stringify/parse work with plain objects. Destructuring and spread (later topics) operate on objects. Reference semantics affect bugs when mutating shared objects.
Interview focus
Be ready to explain these; they come up often in JS interviews.
- ▸Objects are reference types: assignment copies the reference, not the object.
- ▸Shallow copy: spread {...obj}; deep copy: structuredClone or library. When each is needed.
- ▸Dot vs bracket: bracket for dynamic keys, spaces, or symbols.
Learn more
Dive deeper with these trusted resources: