Objects
Objects — The Building Blocks of Everything
If arrays are like a row of lockers (numbered 0, 1, 2...), objects are like a hash map — a filing cabinet with labeled drawers. Each drawer has a name (the key) and something inside (the value).
Objects let you group related data together. A player in a game isn't just a name or just a score — it's both, plus a level, an inventory, and more. Objects let you bundle all of that into one neat package.
Almost everything in JavaScript is an object under the hood — arrays, functions, dates, even errors. Understanding objects is the key to understanding JavaScript itself.
Creating & Accessing Objects
Methods — When Objects Can Do Things
A method is just a function stored as a property of an object. It's what lets objects not only hold data but also do things. When you call console.log(), you're calling the log method on the console object!
Inside a method, the keyword this refers to the object the method belongs to. It's how the method knows which object's data to use.
Methods, Computed Properties & Shorthand
Destructuring, Spread & Useful Methods
Just like arrays, objects support destructuring (pulling out properties into variables) and the spread operator (copying/merging objects).
Three super useful static methods live on Object itself:
Object.keys(obj)— returns an array of all key namesObject.values(obj)— returns an array of all valuesObject.entries(obj)— returns an array of[key, value]pairs (great for looping!)
Destructuring, Spread & Object.keys/values/entries
Quick check
Continue reading