Object.keys
Returns an array of property names.
Object management tools help you inspect, copy, freeze, merge and loop through object data safely.
const settings = { theme: "dark", compact: true };
console.log(Object.keys(settings));
console.log(Object.entries(settings));
Objects, Prototypes & Classes
Object.keys, Object.values and Object.entries convert object structure into arrays, which makes objects easier to inspect and render.
Spread syntax and Object.assign can create shallow copies or merge objects. This is common in state updates and configuration defaults.
Object.freeze can prevent direct changes to an object. It is shallow, so nested objects are still mutable unless they are frozen too.
Returns an array of property names.
Returns an array of property values.
Returns key-value pairs for loops and rendering.
Prevents direct changes to an object.
Examples
const defaults = { theme: "light", compact: false };
const input = { compact: true };
const settings = { ...defaults, ...input };
const defaults = { theme: "light", compact: false };
defaults.compact = true;
// Every caller using defaults now sees changed state.
Code patterns
These patterns focus on the pieces developers actually reuse: object literals, methods, constructors, prototypes, getters, copying, classes and inheritance.
Read property names as an array.
const settings = { theme: "dark", compact: true };
console.log(Object.keys(settings));
Loop over key-value pairs.
const settings = { theme: "dark", compact: true };
for (const [key, value] of Object.entries(settings)) {
console.log(key, value);
}
Later properties overwrite earlier ones.
const defaults = { theme: "light", compact: false };
const userSettings = { theme: "dark" };
const settings = { ...defaults, ...userSettings };
Prevent direct mutation for a shallow object.
const settings = Object.freeze({
theme: "dark",
compact: true
});
Rules that matter
Objects are where JavaScript programs start to model real application state. Good object shape makes later functions, classes and UI updates much easier to maintain.
Key-value pairs are useful for tables and lists.
Avoid changing shared configuration objects.
Nested objects are still shared.
It protects direct writes on the object itself.
It avoids prototype-chain confusion.
Consistent property names make code easier to optimize and read.
Production thinking
Object management is where data becomes inspectable. These tools help transform object shape into arrays, UI and safe copies.
Rendering object entries can power clear definition lists or settings panels with proper labels.
Production code should avoid accidental mutation of defaults, shared config and imported constants.
Stable content objects make metadata rendering predictable across pages.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Object-oriented JavaScript becomes much easier when you can explain where the data lives, where the method is found and which object receives this.