Free tools Windows power users keep installed
One-click scans. No signup required.
JavaScript objects are more than bags of values: property lookup can reach a prototype, enumeration methods include different sets of keys, and freezing an object does not freeze objects nested inside it. These five points explain how to access, inspect, and constrain object properties without relying on assumptions from other languages.
1. An object is a collection of properties
A property associates a key with a value. In this object literal, name is an own property of user:
As an Amazon Associate I earn from qualifying purchases.
const user = { name: "Rae" };
The value can be a string, another object, or a function. A function stored on an object is commonly called a method. See MDN’s guide to working with objects.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems2. Dot and bracket notation access properties differently
Use dot notation when the property name is a valid identifier and known in the code. Bracket notation accepts a string or a key held in a variable, so it works for dynamic names and names that cannot be written as dot-notation identifiers.
#1 Best Overall
const user = { name: "Rae", "favorite color": "blue" };
const field = "name";
user.name; // "Rae"
user["name"]; // "Rae"
user[field]; // "Rae"
user["favorite color"]; // "blue"
Bracket notation is especially useful when data determines which property to read. An object’s prototype can also be chosen when creating it: Object.create(proto) creates an object whose prototype is proto; passing null creates one with no prototype.
3. A property can be found without being owned
Reading a property follows the prototype chain. If the object does not have the requested property itself, JavaScript checks its prototype and continues upward. Most ordinary objects inherit from Object.prototype, so a property can be accessible even when it is not a direct property.
Rank #2
const user = { name: "Rae" };
"toString" in user; // true: found through the prototype chain
Object.hasOwn(user, "toString"); // false: not an own property
Use Object.hasOwn(obj, key) when the question is whether the object itself has a property. The in operator answers a broader question: whether the property exists on the object or anywhere in its prototype chain. An own property can also shadow an inherited property with the same name. MDN explains property ownership and enumerability.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Object.hasOwn is also safer than calling obj.hasOwnProperty(key): an object may have its own property named hasOwnProperty, hiding that inherited method.
4. Enumeration methods return different sets of properties
Choosing how to inspect an object depends on three questions: do you want own or inherited properties, enumerable or non-enumerable properties, and string keys or symbols? These methods do not all answer the same question.
| Method | Own or inherited | Enumerable or non-enumerable | Key types |
|---|---|---|---|
Object.keys(obj) |
Own only | Enumerable only | String keys |
Object.values(obj) |
Own only | Enumerable only | Values for own string-keyed properties |
Object.entries(obj) |
Own only | Enumerable only | Pairs for own string-keyed properties |
for...in |
Own and inherited | Enumerable only | String keys |
Reflect.ownKeys(obj) |
Own only | Enumerable and non-enumerable | String and symbol keys |
For a plain record’s enumerable own string keys, Object.keys is often the right choice. A for...in loop can also visit enumerable properties inherited from prototypes. If using it but you want only direct properties, check each key with Object.hasOwn:
Rank #4
for (const key in obj) {
if (Object.hasOwn(obj, key)) {
// Work with this own enumerable string key.
}
}
Symbols and non-enumerable properties are outside the scope of Object.keys, Object.values, and Object.entries. Use Reflect.ownKeys when you need every own string and symbol key, or use symbol- and descriptor-specific APIs when you need to inspect a particular category. See MDN’s enumeration reference.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 115. Freezing an object does not freeze its nested objects
Object.freeze(obj) prevents adding or removing properties and changing existing property descriptors or data-property values on that object. It does not recursively freeze objects referenced by its properties.
Best Value
const settings = {
display: { theme: "light" }
};
Object.freeze(settings);
settings.display.theme = "dark"; // The nested object is still mutable.
The outer object is frozen, but settings.display still refers to a separate object that remains mutable. If nested objects also need to be frozen, each must be frozen separately; a single call does not make an entire object tree deeply immutable. For the method’s behavior and limitations, see MDN’s Object.freeze() reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




