Basics
Objects
Key-value collections — the building block of JS.
1. Explanation
Objects store related data as key-value pairs. Access values with dot or bracket notation. Use Object.keys / values / entries to iterate. Spread (...) clones or merges objects. Destructuring pulls properties into variables.
2. Example
Try it yourself
Console
Click Run to see output.
3. Expected output
output
Aman
22
Aman 22
{"name":"Aman","age":23,"skills":["html","css","js"]}4. Common mistakes
- ✗Using = to 'copy' an object — you only copy the reference, not the data
- ✗Forgetting that Object.keys returns strings only, not symbols
- ✗Trying to JSON.stringify an object with circular references
5. Practice questions
- Create a 'book' object with title, author, year and log each property
- Use destructuring to extract two properties at once
- Merge two objects using the spread operator